Skip to main content
sd0123
Known Participant
April 24, 2020
Answered

Get Text from Two Fields to Show in Third Field

  • April 24, 2020
  • 2 replies
  • 745 views

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;

}

This topic has been closed for replies.
Correct answer ls_rbls

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"]);

 

 

2 replies

ls_rbls
ls_rblsCorrect answer
Adobe Expert
April 26, 2020

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"]);

 

 

sd0123
sd0123Author
Known Participant
April 27, 2020

Thank you so much!

ls_rbls
Adobe Expert
April 27, 2020

You're welcome

ls_rbls
Adobe Expert
April 25, 2020

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;