Skip to main content
Known Participant
October 11, 2024
Answered

Require code not to be a calculation

  • October 11, 2024
  • 2 replies
  • 1693 views

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.

 

 

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

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.

2 replies

try67
Community Expert
Community Expert
October 11, 2024

What happens when you use it as a Validation script?

Known Participant
October 11, 2024

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
try67
Community Expert
Community Expert
October 11, 2024

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.

PDF Automation Station
Community Expert
Community Expert
October 11, 2024

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

Known Participant
October 11, 2024

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
PDF Automation Station
Community Expert
Community Expert
October 11, 2024

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.