-
Notifications
You must be signed in to change notification settings - Fork 52
Script: ToFirstOrLastname
SamuelPlentz edited this page Jul 2, 2022
·
1 revision
This script allows to combine firstname and lastname into one placeholder, using the lastname as fallback if the firstname is not defined. There is a variant of this script called ToNickname.
var data = this.mQuicktext.process_to(mVariables);
// use lastname if firstname is not available
if(typeof data['firstname'] == 'undefined') {
data['firstname'] = [];
}
for(var i = 0; i < data['lastname'].length; i++) {
if(typeof data['firstname'][i] == 'undefined' || data['firstname'][i] == '') {
data['firstname'][i] = data['lastname'][i];
}
}
if(typeof data['firstname'] != 'undefined') {
if(mVariables.length < 1) mVariables[0] = ", ";
return data['firstname'].join(mVariables[0].replace(/\\n/g, "\n").replace(/\\t/g, "\t"));
} else return "";
Assuming you want to write an email to persons like John Doe (firstname John, lastname Doe) and JLY7 (firstname empty, lastname JLY7).
Using this script in your template:
Hello [[SCRIPT=ToFirstOrLastname|, hello ]],
would resolve to:
Hello John, hello JLY7,