Views:

This example demonstrates how to create lookups which will automatically add a spacer symbol to the lookup ONLY if the spacer is required.
 

Problem


You create a signature configuration using the (!PhoneAndDescription!), (!FaxAndDescription!) and (!MobileAndDescription!) lookups to add the  |  symbol as a separator.

This works ok when at least there is some static text which is guaranteed to exist, if not you may end up with an out of place separator.

e.g. the lookups are configured to append the separator when the text exists.


Signature configuration




If the user does not have a mobile number the following will occur:



The  |  symbol appears at the end of the line
 

Solution


To resolve this the lookups need to know if the lookups preceding them have added any information to the line. This is achieved by having the lookup set and examine a field in the email.

The lookups need to be modified as follows:



strMobile:='(!Mobile!)';@If(strMobile='';'';strMobile + @If(CW_ADDED='Y';' | ';'')+ @Do(@SetField('CW_ADDED';'Y');''))
 

NOTE: Lookups are evaluated line by line from Right to Left.


Therefore in the above signature configuration example the following occurs:
 

1. (!MobileAndDescription!) is evaluated.

2. If the mobile number existed then the following formula is executed.


@If(CW_ADDED='Y';' | ';'')+ @Do(@SetField('CW_ADDED';'Y');'')

If the field CW_ADDED exists then output the '|  symbol (since this is the first lookup executed the field does not exists)

Next the + @Do(@SetField('CW_ADDED';'Y');'') code is executed, this does not any text to the lookup but sets the CW_ADDED flag to the email. This flag is only set if the mobile number existed.


3. The line then becomes (!PhoneAndDescription!)(!FaxAndDescription!)

 

NOTE: In our example there is no mobile number


4. The (!FaxAndDescription!) lookup is now executed. Again the CW_ADDED flag does not exists as the preceding lookups did not set the flag.

 


5. The line now becomes (!PhoneAndDescription!)+64 (0)9 379 7045

6. The (!PhoneAndDescription!) lookup is now executed. This detects the CW_ADDED flag set by the (!FaxAndDescription!) lookup and outputs the  |  symbol.

7. The final line then becomes

+64 (0)9 379 7044 | +64 (0)9 379 7045
 

 

The above formula is designed to allow the lookups (!PhoneAndDescription!), (!MobileAndDescription!) and (!FaxAndDescription!) to work in any order.

Related Products: CMS DOM v4