Highlighted

Help with JavaScript for Subtraction

Community Beginner ,
Oct 26, 2020

Copy link to clipboard

Copied

Hello, I'm learning JavaScript as I go and it is starting to make more sense.  

 

So I tried the following JavaScript as simplified field notation, but it is not doing the math correctly.

Number(this.getField("! Total Revenue").value - Number(this.getField("!S6 Subtotal SFA Costs").value - Number(this.getField("!Total FSMC Costs").value;

 I had started with this JavaScript, but I was getting an error.

event value = Number(this.getField("! Total Revenue").value - Number(this.getField("!S6 Subtotal SFA Costs").value - Number(this.getField("!Total FSMC Costs").value;

 I am trying to get the profit/loss by taking the field ! Total Revenue - !S6 Subtotal SFA Costs - !Total FSMC Costs.  And yes, I now know I should have done my field names differently but I had those set before I ever knew I needed to learn how to do JavaScript thus using the this.getField.

 

Any help would be appreciated.

TOPICS
PDF forms

Views

109

Likes

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

Help with JavaScript for Subtraction

Community Beginner ,
Oct 26, 2020

Copy link to clipboard

Copied

Hello, I'm learning JavaScript as I go and it is starting to make more sense.  

 

So I tried the following JavaScript as simplified field notation, but it is not doing the math correctly.

Number(this.getField("! Total Revenue").value - Number(this.getField("!S6 Subtotal SFA Costs").value - Number(this.getField("!Total FSMC Costs").value;

 I had started with this JavaScript, but I was getting an error.

event value = Number(this.getField("! Total Revenue").value - Number(this.getField("!S6 Subtotal SFA Costs").value - Number(this.getField("!Total FSMC Costs").value;

 I am trying to get the profit/loss by taking the field ! Total Revenue - !S6 Subtotal SFA Costs - !Total FSMC Costs.  And yes, I now know I should have done my field names differently but I had those set before I ever knew I needed to learn how to do JavaScript thus using the this.getField.

 

Any help would be appreciated.

TOPICS
PDF forms

Views

110

Likes

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
Oct 26, 2020 0
Adobe Community Professional ,
Oct 26, 2020

Copy link to clipboard

Copied

You miss many ) characters.

Likes

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
Reply
Loading...
Oct 26, 2020 0
Most Valuable Participant ,
Oct 26, 2020

Copy link to clipboard

Copied

Also a "." between "event" and "value"...

Likes

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
Reply
Loading...
Oct 26, 2020 0
Adobe Community Professional ,
Oct 26, 2020

Copy link to clipboard

Copied

Simplified field notation didn't requires JavaScript keywords, and requires blank spaces (and dots) in fields names to be escaped with a backslash, like this:

 

!\ Total\ Revenue - !S6\ Subtotal\ SFA\ Costs - !Total\ FSMC\ Costs

Likes

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
Reply
Loading...
Oct 26, 2020 0
Contributor ,
Oct 26, 2020

Copy link to clipboard

Copied

That won't work.

Likes

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
Reply
Loading...
Oct 26, 2020 0
Adobe Community Professional ,
Oct 26, 2020

Copy link to clipboard

Copied

JavaScript requires parentheses to be closed:

 

event.value = Number(this.getField("! Total Revenue").value) - Number(this.getField("!S6 Subtotal SFA Costs").value) - Number(this.getField("!Total FSMC Costs").value);

Likes

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
Reply
Loading...
Oct 26, 2020 1
Community Beginner ,
Oct 26, 2020

Copy link to clipboard

Copied

Thank you this worked for me.  I knew something was missing, but given I don't understand JavaScript I didn't know what was missing.  

Likes

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
Reply
Loading...
Oct 26, 2020 1
Adobe Community Professional ,
Oct 26, 2020

Copy link to clipboard

Copied

Since you mentioned you wanted to use simplified field notation, you don't use JavaScript there. You're going to have a problem with it if you use an exclamation point in the fieldname. Some non-alphanumeric characters (e.g., spaces) can be escaped with a backslash, like:

 

Total\ Revenue - S6\ Subtotal\ SFA\ Costs - Total\ FSMC\ Costs

 

But the exclamation points would need to be removed from the fieldnames for this option to work.

Likes

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
Reply
Loading...
Oct 26, 2020 0
Community Beginner ,
Oct 26, 2020

Copy link to clipboard

Copied

It wasn't that I wanted to use Simplified Field Notation that was what I tried.  Because I'm not going to change the Field Names I went with the Java Script.

Likes

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
Reply
Loading...
Oct 26, 2020 0