## Custom Calculation Script

Community Beginner ,
Aug 25, 2017

Copied

Need help writing a custom calculation script.  The script needs to be written so that if "Field1" = 80 and "Field2" = 10 then it returns John, but if "Field1" = 99 and "Field2" = 75, then it returns Jane.

I tried using some other scripts that I found, but they wouldn't work.  It would usually just always return the value of my first "if statement" regardless of whether it was true or not".

Also this is for Acrobat Standard DC.

Thanks!

TOPICS
Acrobat SDK and JavaScript, Windows

Views

348

Likes

Report

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

## Custom Calculation Script

Community Beginner ,
Aug 25, 2017

Copied

Need help writing a custom calculation script.  The script needs to be written so that if "Field1" = 80 and "Field2" = 10 then it returns John, but if "Field1" = 99 and "Field2" = 75, then it returns Jane.

I tried using some other scripts that I found, but they wouldn't work.  It would usually just always return the value of my first "if statement" regardless of whether it was true or not".

Also this is for Acrobat Standard DC.

Thanks!

TOPICS
Acrobat SDK and JavaScript, Windows

Views

349

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 25, 2017 0
5 Replies 5
Most Valuable Participant ,
Aug 25, 2017

Copied

Try this:

`var v1 = Number(this.getField("Field1").value);var v2 = Number(this.getField("Field2").value);if (v1==80 && v2==10) event.value = "John";else if (v1==99 && v2==75) event.value = "Jane";`

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 25, 2017 1
Community Beginner ,
Aug 25, 2017

Copied

Hmm.  Not having luck with that.  I'll try being a little more specific.  Field1 is actually titled Customer Office Code and field2 is titled Department.

Let's assume this is what I need it to return:

If Customer Office Code = "90 - Maine", and Department = "12 - Maintenance" = John Doe

and Customer Office Code = "80 - Ohio, and Department = "15 - Tech" = Jane Doe

Would that change how the code needs to be written?

Thank you again!

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 25, 2017 0
Most Valuable Participant ,
Aug 26, 2017

Copied

`var v1 = this.getField("Customer Office Code").valueAsString;  var v2 = this.getField("Department").valueAsString;  if (v1=="90 - Maine" && v2=="12 - Maintenance") event.value = "John Doe";  else if (v1=="80 - Ohio" && v2=="15 - Tech") event.value = "Jane Doe";`

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 26, 2017 1
Community Beginner ,
Aug 26, 2017

Copied

Yes!  This is what I was looking for.  Now is there a way to add a catch all?  Meaning if they try choosing a selection that doesn't fit the script then it will say "invalid combo"?

Also, is there a limit to the number of combinations that can be included in the script?

Thank you!!!

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 26, 2017 0
LATEST
Most Valuable Participant ,
Aug 26, 2017

Copied

1. At the end of the code add this:

else {

}

I also recommend you add this line before the first if-condition:

event.value = "";

2. No, there's no limit to the number of combinations.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 26, 2017 0