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

Require code not to be a calculation

New Here ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

A while ago Nesa (thank you again) supplied me with a piece of code which worked when entered into the 'Custom Calculation Script' of the dropdown field.

 

if(event.value == "select") {
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.hidden;
}
else if(event.value == "no") {
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.hidden;
}
else if(event.target.value == "yes"){
var nRslt = app.alert ("If this is an out of area deal, do you require the Logbook first being registered to ******  LTD?\n\nIf 'Yes' please make sure the customer is aware they will not be the first keeper on the logbook.",2,2);
if(nRslt == 4){
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.visible;}
else{
this.getField("Group1234").display=display.visible;
this.getField("Group12345").display=display.hidden;}
}

 

However the alert window created by the script keeps appearing when you try and enter text into any field afterwards and I am unable to make the script work in either 'Actions > Run a Javascript' or 'Run Custom validation Script'

I have moved the calculation order so that the dropdown field is the very last field in the list, but the script still runs when you manipulate any field/dropdown after this dropdown field.

 

Is there an additional piece of script that i can add which will stop it from running after the selection of No/Yes has been made or is there another place that the code can be added to stop it from being seen as a calculation.

 

 

------------------------------------------------------------------------
[Sighs] - Trying my hardest to learn all this
TOPICS
JavaScript , PDF forms

Views

603

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

If your values are "select", "yes" and "no" use like this as 'Validate' script:

 

 

if(event.value == "Select" || event.value == "No") {
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.hidden;
}
else if(event.value == "Yes"){
var nRslt = app.alert ("If this is an out of area deal, do you require the Logbook first being registered to ******  LTD?\n\nIf 'Yes' please make sure the customer is aware they will not be the first keeper on the logbook.",2,2);
if(nRslt == 4){
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.visible;}
else{
this.getField("Group1234").display=display.visible;
this.getField("Group12345").display=display.hidden;}
}

 

 

If that doesn't work, check what are exact values in dropdown or share your file.

EDIT: your values are "Select", "Yes", "No", JavaScript is case-sensitive (I updated script above with actual values).

EDIT2: remove export values.

View solution in original post

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

Try removing .target from this line:

else if(event.target.value == "yes")

It wouldn't work in an Action unless you changed all the event's to this.getField("YourDropdownFieldName")

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

Thank for the advice but no joy.

else if(event.value == "yes") - still results in the appalert popping up everytime a field is populated after this dropdown selection has been made when yes is selected.

 

------------------------------------------------------------------------
[Sighs] - Trying my hardest to learn all this

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

That's because the calculations run every time any field value changes.  If the dropdown pops an alert when the value is "yes", the alert will pop every time you change a field value in another field when the dropdown value is "yes".  My suggestion.

-Change all event words to this.getField("YourDropdownFieldName"), example event.value to this.getField("Dropdown").value (assuming the dropdown field name is dropdown).

-Remove the script from the dropdown and put it in a custom calculation script in any text field.

-Add the following to the beginning of your script:

 

 

if(event.source && event.source.name=="Dropdown1")
{

 

 

Add the following to end of your script:

 

 

}

 

 

The script will only run when the dropdown value is changed from the dropdown, not when other field values change.  Thank you to @Nesa Nurani for this trick.

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

Changing the events as you noted, kind of works however when you select 'Yes' from the dropdown you have to  click in the dropdown field a second time to get the appalert to pop up.  If the person filling the form in changes their mind and clicks back on the dropdown to amend their choice they have to go through the popup again before they are allowed to change the dropdown choice.

 

if(this.getField("regyn").value == "select") {
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.hidden;
}
else if(this.getField("regyn").value == "no") {
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.hidden;
}
else if(this.getField("regyn").value == "yes"){
var nRslt = app.alert ("If this is an out of area deal, do you require the Logbook first being registered to ****** LTD?\n\nIf 'Yes' please make sure the customer is aware they will not be the first keeper on the logbook.",2,2);
if(nRslt == 4){
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.visible;}
else{
this.getField("Group1234").display=display.visible;
this.getField("Group12345").display=display.hidden;}
}

------------------------------------------------------------------------
[Sighs] - Trying my hardest to learn all this

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

What happens when you use it as a Validation script?

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

With the original script (using events.value)

When you initially click the drop down the options appear
select, No , Yes

Clicking 'No' has no affect as required

Clicking 'Yes' has no affect - Appalert should trigger but does nothing (commit immediately is selected)

Trying to select anything in the dropdown after you have selected 'Yes' now triggers the Appalert, the 'Yes' 'No' options on the alert work as inteded.

Clicking the drop down and choosing 'Select' or 'No' now do not do anything (do not clear any of the visible fields from the appalert)

Clicking 'Yes' repeats the steps above

------------------------------------------------------------------------
[Sighs] - Trying my hardest to learn all this

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

You have to make sure that your code matches the values, EXACTLY. If the value is "Yes", but your code says "yes", it won't work. Nor if your code says "yes " (with a space after it), etc.

I see no reason it shouldn't work as a validation script. If you've made sure the values match perfectly and it still doesn't work, share the file for further help.

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

Thank yo Try67

The code works perfectly in the custom calculation script, its just that it triggers the appalert on every field entry (before or after)  this dropdown field.  

I have copied it over to the validation script tab and checked all export values again.  They are all correct and morror exactly what is on the script.

 

There is a lot going on in here, the issue is Reg Plate dropdown field.

------------------------------------------------------------------------
[Sighs] - Trying my hardest to learn all this

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

The Calculation script uses the Export Values, while the Validation uses the Display Values. Why have them be different in this way (Select/select, Yes/yes, No/no...)? It doesn't make sense. Remove the Export values and adjust the code accordingly, and it will work.

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

PS. There are plenty of other errors in your code. Check the JS Console.

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

Thank you Try67,

 

Im sure there are major amounts of code that could be removed/cleaned up but i need to read up on how to use JS Console as I (obviously) have never used it

------------------------------------------------------------------------
[Sighs] - Trying my hardest to learn all this

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

See: https://acrobatusers.com/tutorials/javascript_console

But just by opening it (Ctrl+J) you will see multiple errors, after you update one of the fields.

Unfortunately, Adobe made it much more difficult to debug such errors since it removed the name of the field that triggered them, as well as the name of the field that was called in this type of error:

TypeError: this.getField(...) is null

42:Field:Calculate

So all you can know from this is that in line 42 of some calculation script you're attempting to access an invalid field name...

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

LATEST

Yes, the replacement of the field name with "..." in these errors was a huge minus to the application.

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

If your values are "select", "yes" and "no" use like this as 'Validate' script:

 

 

if(event.value == "Select" || event.value == "No") {
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.hidden;
}
else if(event.value == "Yes"){
var nRslt = app.alert ("If this is an out of area deal, do you require the Logbook first being registered to ******  LTD?\n\nIf 'Yes' please make sure the customer is aware they will not be the first keeper on the logbook.",2,2);
if(nRslt == 4){
this.getField("Group1234").display=display.hidden;
this.getField("Group12345").display=display.visible;}
else{
this.getField("Group1234").display=display.visible;
this.getField("Group12345").display=display.hidden;}
}

 

 

If that doesn't work, check what are exact values in dropdown or share your file.

EDIT: your values are "Select", "Yes", "No", JavaScript is case-sensitive (I updated script above with actual values).

EDIT2: remove export values.

Votes

Translate

Translate

Report

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 ,
Oct 11, 2024 Oct 11, 2024

Copy link to clipboard

Copied

Thank you Nesa,
That worked perfectly.

------------------------------------------------------------------------
[Sighs] - Trying my hardest to learn all this

Votes

Translate

Translate

Report

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