Copy link to clipboard
Copied
Hi there
Trying to create a form to where in one cell, they place the person's name - Chandler, Michael Stevens
Then another cell references that cell, and I want it to just have Chandler and anything after the , is truncated. I tried to search online for this but the formula I found does not work 100%. Any help would be greatly appreciated.
Copy link to clipboard
Copied
You can use this script as a Validation script in the field where they place the person's name:
aTexte = event.value; // get the value
aTexte = aTexte.split(" "); // use the blank space to split the value into array
aTexte = aTexte.shift(); // get the first element of the array
aTexte = aTexte.replace(",", ""); // remove the comma if exist
this.getField("targetTextFieldName").value = aTexte; // assign the resulting value to the target field
Copy link to clipboard
Copied
You are awesome! Thank you. Side question....
So, another thing I am wanting to see if is possible...
Have a drop down of various salutations:
Dear Mr. & Mrs..
Dear Mr.
Dear Mrs. & Mrs.
Etc. But, depending on the drop down, have the field that pulls just the last name, to where it reads:
Dear Mr. & Mrs. Chandler
This will allow for the text to all flow as a normal letter and not a huge gap. Thank you!!
Copy link to clipboard
Copied
Instead of the above use this code as the custom calculation script of the text field (adjust the field names as needed in the code):
var fullName = this.getField("FullName").valueAsString;
var prefix = this.getField("Prefix").valueAsString;
if (fullName!="") {
var surname = fullName.split(",")[0];
event.value = prefix + " " + surname;
} else event.value = "";
Edit: Code fixed
Copy link to clipboard
Copied
I am trying the above script but getting the following error. Thank you @GalacticRailroad - you've helped me on other situations in the past so thank you again!!!
Copy link to clipboard
Copied
The screenshot is cut off... But I think I know what it is.
Change this line:
if (fullName!="")
To:
if (fullName!="") {
Copy link to clipboard
Copied
You're awesome. Thank you. So curve ball now - say they want to add in their own salutation that may be out of the norm and something no on the list... i.e. Dr. & Mrs or Mr. & Ms. .... a list of possible salutations could become quite lengthy. Cause with this code, if I go in and try to type in my own greeting, it reverts back to what is selected from above. Much thanks and respect for your knowledge!
Copy link to clipboard
Copied
You can set the drop-down field to accept custom user input, under its Properties - Options tab.
The script will work the same with either a selected value or a manually entered one.