Skip to main content
Participant
January 23, 2023
Answered

How do I write Java to populate TEXT in a field based off a chosen item in a drop down menu?

  • January 23, 2023
  • 2 replies
  • 1781 views

I built a form for work that contains a drop down list. Based off the drop down item chosen, I want specific descriptive text to auto-populate in a text field. 

 

I wrote the JAVA script and got the first one to work, but I can't get the others to. 

 

Here is what I have:

var SkillObserved = this.getField("SkillObserved").valueAsString;

var Expectation = this.getField("Expectation").valueAsString;

if (SkillObserved == "HEART") {
Expectation = "De-escalating tense situations requires all team members to use the HEART method. Regardless of order, all steps must be taken. This is important because HEART uses tools to engage with an upset guest in a way that promotes a positive experience. By doing this, we are aligning with the health system's recommendation for customer service.";
}

else if (SkillObserved == "Two Patient Identifiers") {
Expectation = "We expect all team members to utilize two distinct identifiers. It is important that two unique identifiers are selected and open-ended questions are utilized to obtain the response. This is to eliminate any safety events related to incorrect patient identification.";
}

else if (SkillObserved == "In Person Guest") {
Expecation = "All pharmacy staff must greet guests using our standard greeting. Standard greetings enhance reliability, professionalism, and service.";
}

else if (SkillObserved == "Incoming Call") {
Expectation = "All pharmacy staff must greet guests using our standard greeting. Standard greetings enhance reliability, professionalism, and service.";
}

esle{}

this.getField("Expectation").value = Expectation;

This topic has been closed for replies.
Correct answer Nesa Nurani

Some of values are not same in script as they are in dropdown field like:
in script you used "In Person Guest" while in field it's "In-Person Greeting"
same for "Incoming Call" while in field it's "Incoming Call Greeting" plus all of choices have export value and you have few errors in your script.
I would remove document level script and place this in dropdown field under validation tab -> 'Run a custom validation script':

var Expectation = this.getField("Expectation");

if (event.value == "HEART") {
Expectation.value = "De-escalating tense situations requires all team members to use the HEART method. Regardless of order, all steps must be taken. This is important because HEART uses tools to engage with an upset guest in a way that promotes a positive experience. By doing this, we are aligning with the health system's recommendation for customer service.";
}

else if (event.value == "Two Patient Identifiers") {
Expectation.value = "We expect all team members to utilize two distinct identifiers. It is important that two unique identifiers are selected and open-ended questions are utilized to obtain the response. This is to eliminate any safety events related to incorrect patient identification.";
}

else if (event.value == "In-Person Greeting" || event.value == "Incoming Call Greeting") {
Expectation.value = "All pharmacy staff must greet guests using our standard greeting. Standard greetings enhance reliability, professionalism, and service.";
}

else
Expectation.value = "";

Also in dropdown field properties under 'Options' tab, check 'Commit selected value immediately'.

Here is your file with changes made:

https://drive.google.com/file/d/1h-ODYkJ_7aRCW9YpmkuY_UpH9pcwdN26/view?usp=share_link 

2 replies

Bernd Alheit
Community Expert
Community Expert
January 24, 2023

Check the JavaScript console for errors.

Where does you use the script?

Thom Parker
Community Expert
Community Expert
January 23, 2023
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
January 24, 2023

Thank you, Thom. I looked through the thread. Tried several of the "solves" and none of them worked for me. I'm sure it's user error, but any personalized help is greatly appreciate. 

 

On a more "user friendly note". Maybe you Adobe could do everyone a solid and build a JAVA SCRIPT wizard in Acrobat for situations like this. 

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
January 24, 2023

Some of values are not same in script as they are in dropdown field like:
in script you used "In Person Guest" while in field it's "In-Person Greeting"
same for "Incoming Call" while in field it's "Incoming Call Greeting" plus all of choices have export value and you have few errors in your script.
I would remove document level script and place this in dropdown field under validation tab -> 'Run a custom validation script':

var Expectation = this.getField("Expectation");

if (event.value == "HEART") {
Expectation.value = "De-escalating tense situations requires all team members to use the HEART method. Regardless of order, all steps must be taken. This is important because HEART uses tools to engage with an upset guest in a way that promotes a positive experience. By doing this, we are aligning with the health system's recommendation for customer service.";
}

else if (event.value == "Two Patient Identifiers") {
Expectation.value = "We expect all team members to utilize two distinct identifiers. It is important that two unique identifiers are selected and open-ended questions are utilized to obtain the response. This is to eliminate any safety events related to incorrect patient identification.";
}

else if (event.value == "In-Person Greeting" || event.value == "Incoming Call Greeting") {
Expectation.value = "All pharmacy staff must greet guests using our standard greeting. Standard greetings enhance reliability, professionalism, and service.";
}

else
Expectation.value = "";

Also in dropdown field properties under 'Options' tab, check 'Commit selected value immediately'.

Here is your file with changes made:

https://drive.google.com/file/d/1h-ODYkJ_7aRCW9YpmkuY_UpH9pcwdN26/view?usp=share_link