Copy link to clipboard
Copied
I have three fields: CALicense, ARLicense, and AgentLicense.
I would like AgentLicence to show text from either/both CA and AR License fields depending on which is entered. I’m getting lost on the if condition part of the script – I’m thinking that a check for empty fields is necessary…? Here's the direction I'm thinking of:
var lic1 = this.getField(“CALicense”).value;
var lic2 = this.getField(“ARLicense”).value;
if (lic1 = “” && lic2 = “”){
event.value = “”;
}
if (CALicense has text but not ARLicense){
event.value = “CA License #” + lic1;
}
If (RALicense has text but not CALicense){
event.value = “ARLicense #) + lic2;
}
If (both CALicense and ARLicense both have text)}
event.value = “CA License #” + lic1 + “ & ARLicense #” + lic2;
}
I apologize, please disregard my prior reply. I did a mistake in the code example.
This is what is working on my end:
var d = this.getField("CALicense").valueAsString;
var e = this.getField("ARLicense").valueAsString;
var f = this.getField("AgentLicense").valueAsString;
if ( (d != "") && (e === "") ) event.value = " CA License " + d;
else if ( (e != "") && (d === "") ) event.value = " AR License " + e;
else if ( (d != "") && (e != "") ) event.value = " CA License " + d + " AR License ";
else
...
Copy link to clipboard
Copied
Hi,
You can try the code below. Note that I fixed a few things, like spacing, proper syntax, and the use of quotes.
Ensure that the quotes that you're using are straight. Javascript may misinterpret it if a different font type is used.
Just copy the script below and use it as the custom calculation script of the Agent License text field.
var lic1 = this.getField("CALicense").valueAsString;
var lic2 = this.getField("ARLicense").valueAsString;
if (lic1 && lic2 =="") event.value ="";
else if ((lic1 !="") && (lic2 =="")) event.value = "CA License # " + lic1;
else if ((lic2 != "") && (lic1 =="")) event.value = "ARLicense # " + lic2;
else if (lic1 && lic2 != "") event.value = "CA License # " + lic1 + " & ARLicense # " + lic2;
Copy link to clipboard
Copied
I apologize, please disregard my prior reply. I did a mistake in the code example.
This is what is working on my end:
var d = this.getField("CALicense").valueAsString;
var e = this.getField("ARLicense").valueAsString;
var f = this.getField("AgentLicense").valueAsString;
if ( (d != "") && (e === "") ) event.value = " CA License " + d;
else if ( (e != "") && (d === "") ) event.value = " AR License " + e;
else if ( (d != "") && (e != "") ) event.value = " CA License " + d + " AR License ";
else if ( (e === "") && (d === "") ) event.value = this.resetForm(["AgentLicense"]);
Copy link to clipboard
Copied
Thank you so much!
Copy link to clipboard
Copied
You're welcome