To generate a nice and personal invitation email or startpage for your questionnaire, you probably want to address each respondent with a proper salutation.

Provided you have columns representing "First name", "Last name" and "Gender" present and filled in your datagarden, you can have the following script combine this information and create a nice salutation out of it, which you can use by means of a fieldpicker.



Let’s say you have columns in the datafile like displayed in the image below and you wish to create a salutation like "miss E. Emerson" or "mister B. Bishop".

This column may have entries like Aaron, Alexander and m or v as markings for gender. To create the salutation, you would first need to create a new definition named "Salutation" to store the salutation of a contact.

Next you need to create the following creation rule in the rule tab of the proper datagarden database.

Assuming you would want to create a gender-based salutation and replace the first name with an initial you can copy/paste the part between the ***** script ***** markings into your expert rule text area.

The only manual edit you need to perform in the script below is replace the column names “First name", "Last name" and "Gender" (in black) with the names of your own columns.

The first 6 lines of the script are there to declare values.

Line 7 pulls out the first character of the column "First name".

Lines 8, 9 and 10 are used to rename the values of the field "Gender".

Line 11 is used to join the separate columns.

Line 12 removes unwanted white spaces.

Line 12 changes the value of coumn "Salutation" to the newly created salutation.


***** script ****

var TempInitial = DRE.getColumn ("First name");

var TempLastname = DRE.getColumn ("Last name");

var TempGender = DRE.getColumn ("Gender");

var TempGender_long;

var TempSalutation;

var String;

var TempFirst_Char = (Initial.substring(0, 1));


if (TempGender == "m")  {TempGender_long = "sir";}else{

if (TempGender == "v")  {TempGender_long = "miss";}else

{{TempGender_long = "sir or miss"}}};


                              var Str = TempGender_long + " " + TempFirst_Char + ". " + TempLastname;

                              var TempSalutation = (Str.trim());


                              DRE.createOrChangeValueInDB("Salutation", TempSalutation);


***** script ****


 You can see the result below: