Hi,
I want to create salutation text for field "salutation for mail" on Contact's form. I have a field which name is "salutation" and is a OptionSet field. If one option is selected, then the field "salutation for mail" should be filled out with combination of firstname, lastname and Titel.
But these fields ( firstname, lastname and Titel) can be empty.
if i check it in a condition like below, i get "null" in field "salutation for mail" if these fields are empty:
if (Salutation == "" && firstName != null && Titel != null){
formContext.getAttribute("Salutationformail").setValue(Salutation+" "+Titel+" "+firstName+" "+lastName);
}
Does anybody have an idea how can i check these fields for null value so that i dont get null if these are empty?
Thanks
Best Regards!
It works perfect!! exactly what i want.
Thank you so much!
Regards,
Hi Elpibato,
Do you mean there is an extra space between salutation and lastName, right?
Please try this code:
if(Salutation == "yourValue"){
Title = Title != null?" " Title:"";
firstName = firstName != null?" " firstName:"";
formContext.getAttribute("Salutationformail").setValue(Salutation Title firstName " " lastName);
}
Thnaks, it works!
But i have just one problem, if i use this code and titel is empty then i get an empty string between salutation and lastName like this: "Dear Lopez".
Do you have any idea why it seems like this?
Best Regrads,
Hi Elpibato,
I see.
You can try the following code:
if(Salutation == "yourValue"){ Title = Title != null?Title:""; firstName = firstName != null?firstName:""; formContext.getAttribute("Salutationformail").setValue(Salutation " " Title " " firstName " " lastName); }
Thanks for your answer!
I mean if I use this code then i get like this: "Dear Mr. null Lopez"
I dont now how can I avoid this problem if one of these field is empty?
Hi Elpibato,
I'm not sure what does 'Does anybody have an idea how can i check these fields for null value so that i dont get null if these are empty?' mean.
Do you mean that if firstName and lastName are empty, you don't want to get "null" in field "salutation for mail"? So which value do you want to get?
According to the code, you didn't do anything when firstName and lastName are empty. If I misunderstand your question, please correct me.
So you want to set the salutation if all three fields are not null right? You got the condition wrong. It should be:
if (Salutation !== null && Salutation !== undefined && firstName !== null && firstName !== undefined && Titel != null && Titel != undefined) {
formContext.getAttribute("Salutationformail").setValue(Salutation+" "+Titel+" "+firstName+" "+lastName);
}
If this has answered your question please mark it as the answer.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156