Merging different tag fields together under certain conditions

Hi,

I am trying to create an action that stores disc number and total discs as a single string, but only when there is more than 1 disc. In cases where there is only 1 disc then both the total discs and disc number tags should be deleted.

I've tried to break this down into logical steps to cover most eventualities (such as either of the fields being blank), but I'm new and not very good at this sort of thing, so therefore there may be a more effective set of steps to take in order to achieve this (in other words, combining certain steps into a single command where they don't need to be performed separately, or changing the order of steps to prevent any unintended consequences).

I'm thinking about doing it the following way:

1. If the TOTALDISCS field is empty and the DISCNUMBER field is 1 (regardless of any leading zeros) then delete the DISCNUMBER field. This will mean that there will be neither a DISCNUMBER or a TOTALDISCS tag any more.

2. If the DISCNUMBER field is empty and the TOTALDISCS field is 1 (regardless of any leading zeros) then delete the TOTALDISCS field. This will mean that there will be neither a DISCNUMBER or a TOTALDISCS tag any more.

3. If the TOTALDISCS field and the DISCNUMBER field are both 1 (regardless of leading zeros) then delete both TOTALDISCS and DISCNUMBER tags.

4. If the DISCNUMBER value exceeds the TOTALDISCS value (strip any leading zeros) then delete the TOTALDISCS tag so that only the DISCNUMBER tag remains with no leading zeros.

5. If the TOTALDISCS value is the same as or exceeds the DISCNUMBER value then then merge the contents of DISCNUMBER and TOTALDISCS into a single string separated by a forward slash and stored in the DISCNUMBER field (with all leading zeros removed) and then delete the TOTALDISCS tag. This will mean only the DISCNUMBER tag remains, and it will have a value in the format x/y.

I'm assuming that there is no need to state "greater than 1" in step 5 because any tags with value 1 would have already been deleted.

I think I've covered everything, but any advice on the best way to achieve this would be gratefully received.

Thanks!

I think that the first 3 conditions could be summarized to
"If totaldisc is 1 or empty, delete discnumber and totaldisc"
So in a way it is
"If totaldisc is smaller than 2 then delete discnumber and totaldisc"

Step 1..3; 1: TOTALDISCS <== $if($less(%TOTALDISCS%,2),,$num(%TOTALDISCS%,1)) Step 1..3; 2: DISCNUMBER <== $if($less(%DISCNUMBER%,2),,$num(%DISCNUMBER%,1)) ... or ... Step 1..3; 1: TOTALDISCS <== $ifgreater(%TOTALDISCS%,1,$num(%TOTALDISCS%,1),) Step 1..3; 2: DISCNUMBER <== $ifgreater(%DISCNUMBER%,1,$num(%DISCNUMBER%,1),) Step 4 ; 1: TOTALDISCS <== $ifgreater(%DISCNUMBER%,%TOTALDISCS%,,$num(%DISCNUMBER%,1)) Step 5 ; 1: DISCNUMBER <== $ifgreater(%TOTALDISCS%,$sub(%DISCNUMBER%,1),$num(%DISCNUMBER%,1)'/'$num(%TOTALDISCS%,1),%DISCNUMBER%) Step 5 ; 2: TOTALDISCS <== $ifgreater(%TOTALDISCS%,$sub(%DISCNUMBER%,1),,%TOTALDISCS%)

I assume that the result can be achieved in a simpler and shorter way.

DD.20150119.1828.CET

Other proposal ...

Step 1; 1: DISCNUMBER <== $ifgreater(%TOTALDISCS%,$sub(%DISCNUMBER%,1),$num(%DISCNUMBER%,1)'/'$num(%TOTALDISCS%,1),%DISCNUMBER%) Step 1; 2: TOTALDISCS <== $ifgreater(%TOTALDISCS%,$sub(%DISCNUMBER%,1),,%TOTALDISCS%) Step 2; 1: TOTALDISCS <== $if($eql(%DISCNUMBER%,'1/1'),,%TOTALDISCS%) Step 2; 2: DISCNUMBER <== $if($eql(%DISCNUMBER%,'1/1'),,%DISCNUMBER%) ... or ... Step 2; 1: TOTALDISCS <== $if($eql($num(%DISCNUMBER%,1),1),,%TOTALDISCS%) Step 2; 2: DISCNUMBER <== $if($eql($num(%DISCNUMBER%,1),1),,%DISCNUMBER%) ... or ... Step 2; 1: TOTALDISCS <== $ifgreater(2,%DISCNUMBER%,,%TOTALDISCS%) Step 2; 2: DISCNUMBER <== $ifgreater(2,%DISCNUMBER%,,%DISCNUMBER%)

DD.20150119.1910.CET