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.
Copy link to clipboard
Copied
You miss many ) characters.
Copy link to clipboard
Copied
Also a "." between "event" and "value"...
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
Copy link to clipboard
Copied
That won't work.
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);
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.
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.
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.