Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jan 23, 2023 Jan 23, 2023

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;

TOPICS
JavaScript , PDF forms
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jan 24, 2023 Jan 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 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2023 Jan 23, 2023

This is by far one of the most (if not the most) asked question on the forum. See these forum threads.

https://community.adobe.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&...

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2023 Jan 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2023 Jan 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 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2023 Jan 24, 2023
LATEST

Thank you, Nesa!

 

I saw your response on another post about validating the field and used it and it worked beautifully! I appreciate your time!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2023 Jan 24, 2023

Check the JavaScript console for errors.

Where does you use the script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines