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

Java Script for Adobe Acrobat custom calculation

New Here ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

[Moderator moved from Using the Community (forums) to Acrobat.]

 

I am a complete beginner in java for PDFs so any guidance is welcome. I suspect a reasonably competent 5th grader could do this easily but I'm getting no where. Perhaps you can help. 

 

I have a form to help staff develop a savings/spending plan for personal care services under a Medicaid waiver program. It allows the user to calculate the cost to a fixed budget for two workers whose wages can vary and who may or may not have workers comp. This must account for at least 75% of the budget, any remainder can be used to save for good and services not ordinarily covered by Medicaid.

 

The wage calculations result in four separate dollar amounts. Depending on which of the four dollar amounts is selected, I would like that value compared to field Meets75percentofBudget; if the selected field (Selection1, Selection2, Selection3, or Selection4) is less than Meets75percentofBudget I would like it to return he word No. If greater than or equal, I would like it to return the word Yes. 

 

I would also like a separate field MonthlySavings to subtract the dollar amount in (Selection1, Selection2, Selection3, or Selection4) from the amount in field TotalBudgetAmount. 

 

I've been reading tutorials, reference books, and consulting with colleagues but have picked up enough to just confuse me more. I'm reaching a point where this project will have to be abandoned soon due to the time it is taking from other tasks which will mean our mathematically challenged program staff will have to do these simple calculations by hand that is already resulting in errors. All help appreciated! 

TOPICS
How to

Views

1.9K

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
LEGEND ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

A tip. This may seem pendantic, but if you use the wrong words for things, then Google won't find what you need.

 

The scripting language in Acrobat is JavaScript. ALWAYS one word, never Java Script. Never abbreviated to Java. This is particularly important because there is ANOTHER entirely different language called Java, also sometimes used to work with PDF files...

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

You need to better explain how this is set up. Are the "SelectionX" fields text fields, or something like check-boxes? If the former, how is one of them "selected", exactly? If the latter, where is the value to compare coming from?

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

The "SelectX" fields are check boxes. The value to compare to is an adjacent field. Those fields are numeric and named BothWorkerswithWC, BothWorkersWOWC, Worker1withWCandWorker2WOWC, and Worker1WOWCandWorker2withWC. Select1 should trigger a comparison of BothWorkerswithWC to the value in field 75ofBudget then return No to the field Meets75ofBudget if BothWorkerswithWC is less than 75ofBudget, Yes if it is greater than or equal to 75ofBudget. Selection2 should compare BothWorkersWOWC to 75ofBudget, Select3 would compare Worker1withWCandWorker2WOWC and 75ofBudget , Selection3 would compare Worker1withWCandWorker2WOWC to 75ofBudget, and Selection4 would compare Worker1WOWCandWorker2withWC. I recognize that the field names may be unweildy but they're helpful to me. I've attached the form if that helps.

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

OK, that's more clear. However, since the check-boxes should be mutually exclusive I would recommend you give them the same name ("Selection", perhaps), but unique export values (1-4, perhaps). That would allow the user to only select one at a time, and would prevent future problems.

If you do that then you could use the following code as the custom calculation script of Meets75ofBudget:

 

var selection = this.getField("Selection").valueAsString;
var budget75Perc = this.getField("75ofBudget").valueAsString;
if (selection=="Off" || budget75Perc=="") event.value = "";
else {
	var fieldNameToCompare = "";
	if (selection=="1") fieldNameToCompare = "BothWorkerswithWC";
	else if (selection=="2") fieldNameToCompare = "BothWorkersWOWC";
	else if (selection=="3") fieldNameToCompare = "Worker1withWCandWorker2WOWC";
	else if (selection=="4") fieldNameToCompare = "Worker1WOWCandWorker2withWC";
	
	var v1 = Number(this.getField(fieldNameToCompare).valueAsString);
	var v2 = Number(budget75Perc);
	event.value = (v1<v2) ? "No" : "Yes";
}

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

I'm not sure I understand exactly what you mean by "unique export values"; could you give me more guidance on that?

Also, depending on the selection the user makes,  how would I go about subtracting the corresponding field's value from the value in field TotalBudgetAmount to obtain the amount for MonthlySavings in line F?

 

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

It's under Properties - Options.


I suggest you try reading some tutorials about calculations in PDF files, as it seems you have a bunch you need to implement. Here's a good place to start: https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

Thank you. Got the export value figured out.

Have been reading online tutorials, reference manuals, and have spoken to more skilled Acrobat users but just seemed to have hit a wall on these two issues.

I tried your code but neither No nor Yes were returned to the field Meets75ofBudget. Not sure what to look for to determine problem. I don't understand enough about JavaScript syntax.

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 ,
Jun 16, 2021 Jun 16, 2021

Copy link to clipboard

Copied

Check the JS Console for error messages.

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 ,
Jul 02, 2021 Jul 02, 2021

Copy link to clipboard

Copied

LATEST

I have been seen taht things but I need a cool juice wrld phone case  as well after that all things that you dicussed.

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