Scenario: You have to output the final three characters of a field value coming from a datastream however, the string of the value can vary from 3 characters on-wards, i.e. the value is never fixed.
- Open the process.
- Add the variable version of the field you wish to format.
- Right-click on the variable and select Edit Script…
- Insert the following code:
//Places the length of the string into variable $a
// Subtracts 2 from the length
$b = num($a) – 2;
//Variable $1MWWBANO takes the substring of its value based on the subtracted //variable $b as the position and ‘3’ as the number of subsequent places that are //outputted
$1MWWBANO = substr($1MWWBANO,$b,3);
- Click OK.
Export, deploy and test!
- If the field value is 1234567 you will output 567
- IF the field value is 123 you will output 123
- If the field value is 34-4533345689 you will output 689