The "+" operator can concatenate two strings or one can use the concat method
Other considerations include what to do if either or both the names are not filled in..
A full solution could be using a document level script to concatenate up to 3 fields and adjust for any null fields.
// document level function;
// Concatenate 3 strings with separators where needed
function fillin(s1, s2, s3, sep = "") {
/*
Purpose: concatenate up to 3 strings with an optional separator
inputs:
s1: required input string text or empty string
s2: required input string text or empty string
s3: required input string text or empty string
sep: optional separator sting
returns:
sResult concatenated string
*/
// variable to determine how to concatenate the strings
var test = 0; // all strings null
var sResult; // re slut string to return
// force any number string to a character string for input variables
s1 = s1.toString();
s2 = s2.toString();
s3 = s3.toString();
//if(sep.toString() == undefined) sep = ''; // if sep is undefined force to null
/*
assign a binary value for each string present
so the computed value of the strings will indicate which strings are present
when converted to a binary value
*/
if (s1 != "") test += 1; // string 1 present add binary value: 001
if (s2 != "") test += 2; // string 2 present add binary value: 010
if (s3 != "") test += 4; // string 3 present add binary value: 100
/* return appropriate string combination based on
calculated test value as a binary value
*/
switch (test.toString(2)) {
case "0": // no non-empty strings passed - binary 0
sResult = "";
break;
case "1": // only string 1 present - binary 1
sResult = s1;
break;
case "10": // only string 2 present - binary 10
sResult = s2;
break;
case "11": // string 1 and 2 present - binary 10 + 1
sResult = s1 + sep + s2;
break;
case "100": // only string 3 present - binary 100
sResult = s3;
break;
case "101": // string 1 and 3 - binary 100 + 001
sResult = s1 + sep + s3;
break;
case "110": // string 2 and 3 - binary 100 + 010
sResult = s2 + sep + s3;
break;
case "111": // all 3 strings - binary 100 + 010 + 001
sResult = s1 + sep + s2 + sep + s3;
break;
default: // any missed combinations
sResult = "";
break;
}
return sResult;
}
// end document level functon;
// custom field calculation for Client Name;
var cFirstName = this.getField("First Name").value;
var cLastName = this.getField("Last Name").value;
event.value = fillin(cFirstName, cLastName, "", " ");