Here we show you three examples for the Custom Expression.
Example Nr.1
You want to create a virtual field with the name Salutation that contains the title of the person, e.g. Dr. or Dipl.-Ing., and their name.
This is the function you need:
If(StrLength(SourceField(Title)) > 0 , SourceField(Title) & " " & SourceField(First name) & " " & SourceField(Surname), SourceField(First name) & " " & SourceField(Surname))
We will explain this function to you step by step.
A possible output is Dr. John Smith.
The if-function delivers a title and the SourceField(First name) & " " SourceField(Surname) the name of the contact. Both are connected by an &.
For the if-function you have to enter an expression first. It is StrLength(SourceField(Title)) > 0 in this case. StrLength is a function that delivers the length of a string. In this case, if the field is not empty the length/corresponding number is bigger than 0 and the expression is true. Otherwise the expression is false.
Next, there is the value that will appear when the expression is true: SourceField(Title) & " " & SourceField(First name) & " " & SourceField(Surname). That means, the title and the name will be displayed.
After that you see the value that will appear when the expression is false.
And that is how you create the virtual field Salutation.
Example Nr.2
This example is a little more extensive than the first one. Here you can create a field for occassions that have been initiated by an employee in a certain way. In this virtual field, Initiative, Occasion and Employee are listed. This is what the complete function looks like:
"Initiative:" & If(StrLength(SourceField(Initiative))>0, SourceField(Initiative), "-") &
"Occasion:" & If(StrLength(SourceField(Occasion))>0, SourceField(Occasion), "-") &
"Employee:" & If(StrLength(SourceField(Employee))>0, SourceField(Employee), "-")
An if-function consists of three parts.
First there is the expression which is StrLength(SourceField(Initiative))>0 in this case. If the length of the Source Field is bigger than 0 the expression is true.
After that there is the value that will be displayed when the expression is true. Here it is the value of the Source Field Initiative.
In the end you find the value that will appears when the expression is false. This is always the character -.
A possible output of this example function is:
Initiative: -
Occasion: Company anniversary
Employee: Nina Nolte
That is how you create the virtual field Occasion.
Example Nr. 3
If you want to automate your Salutation, meaning that "Dear Mr" or "Dear Mrs" will be inserted depending on the sex entered, you can use the following expression:
If(Equals(SourceField(Sex) , "M", CaseSensitive), "Dear Mr" & " "& SourceField(Name), "Dear Mrs" & " " & SourceField(Name))
If the source field "Sex" contains the value M for male then "Dear Mr" will be inserted in front of the name in the salutation field, otherwise "Dear Mrs" will be inserted.
You can adjust the custom expression accordingly when there are values in the field "Sex" different than the ones above, for example "male" and "female".