Calculating the sum
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2015 11:38 AM
Hello all,
I am working on a new application for a department outside of IT. One of the requirements is that I add the "Amount" field on the child ticket (Table B) to the "Amount" field on the parent ticket (Table A). There can be more than one child ticket but only one parent. My logic is as follows:
Run on: Table B
If "Parent" field is not empty & "Amount" field is not empty
Add "Amount" value from Table B to "Amount" value on Table A
Update Table A "Amount" field with the new sum value
I have tried writing a business rule to accomplish this but I am not having much luck. I was able to use the following script to add two fields from Table B and display the information in a InfoMessage (see image) but not update the field with the sum value.
function onAfter(current, previous) {
var amount1 = current.dec_amt_1;
var amount2 = current.dec_amt_2;
var amount3 = current.dec_amt_3;
gs.addInfoMessage('Amount 1: ' + amount1);
gs.addInfoMessage('Amount 2: ' + amount2);
gs.addInfoMessage('Amount 3: ' + amount3);
if (amount2 != ''){
var newAmount = amount1 + amount2;
gs.addInfoMessage('Amount is: ' + newAmount);
}
}
When I try working with both tables, nothing happens at all.
Can anyone provide some guidance on how to accomplish this?
Thanks in advance,
Sarah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2015 12:18 PM
Tanaji,
You are right - my two fields are not out of box; however, I've just verified that they do not have a prefix.
I've tried creating a new Case and added a Fraud Incident with 'Dec Amt 1' of 100.00. Saving the Fraud Incident did nothing to the 'Amount' field on the Case.
Thanks,
Sarah

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2015 10:40 PM
Hi Sarah,
The code I pasted above was tested one. Let me regenerate it on any of demo instance and check it again.
You can check if it is reading values from the fields by using gs.addInfoMessage() in between your code. Doing this will tell you what the problem is. Whether it is able to access the fields or not.
Thanks,
Tanaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2015 06:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2015 07:47 AM
i think its happening because of the difference in "type" of these fields
Check this link to see how to tackle that
http://wiki.servicenow.com/index.php?title=Scripting_Currency_and_Price_Fields#gsc.tab=0