- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2017 02:48 PM
Here my script:
but not working it..
Business rule: table :incident
var totalA = 0;
totalA += current.u_used_amount;
var bRec = new GlideRecord('u-details');
bRec.query();
if(bRec.next()){
bRec.u_reaming_balance = totalA;
bRec.update();
}
8000+5000+3000=16000 , display result sum in u_details table
Table: u_details
Field: u_remaing_balance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2017 03:34 PM
Hi Srivastav,
(function executeRule(current, previous /*null when async*/) {
var cal = 0;
var gr = new GlideRecord('incident');
gr.addQuery('category', 'software'); // is it mandatory ??
gr.query();
while(gr.next())
cal = parseInt(cal) + parseInt(gr.u_used_amount);
var bRec = new GlideRecord('u_details');
bRec.addQuery('fieldname', 'pass the filter value here'); //if it is new table of field then the field is empty , WHAT DO NOW
bRec.query();,
if(bRec.next()){
bRec.u_reaming_balance = cal;
bRec.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2017 02:59 PM
You need to do GlideRecord on incident table as well to get the used amount for all the record and then sum them up and then pass to another table u_details.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2017 03:04 PM
Example:
(function executeRule(current, previous /*null when async*/) {
var cal = 0;
var gr = new GlideRecord('incident');
gr.addQuery('category', 'software');
gr.query();
while(gr.next())
cal = parseInt(cal) + parseInt(gr.u_used_amount);
var bRec = new GlideRecord('u_details');
bRec.addQuery('fieldname', 'pass the filter value here');
bRec.query();
if(bRec.next()){
bRec.u_reaming_balance = cal;
bRec.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2017 03:34 PM
Hi Srivastav,
(function executeRule(current, previous /*null when async*/) {
var cal = 0;
var gr = new GlideRecord('incident');
gr.addQuery('category', 'software'); // is it mandatory ??
gr.query();
while(gr.next())
cal = parseInt(cal) + parseInt(gr.u_used_amount);
var bRec = new GlideRecord('u_details');
bRec.addQuery('fieldname', 'pass the filter value here'); //if it is new table of field then the field is empty , WHAT DO NOW
bRec.query();,
if(bRec.next()){
bRec.u_reaming_balance = cal;
bRec.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2017 03:43 PM
gr.addQuery('category', 'software'); // is it mandatory ??
is not mandatory, but if you do not provide the filter then it will query the whole incident record to calculate the value. take appropriate action as per the business requirement, if you want to calculate for all the incident records then you do not need to provide filter else please consider to include.
bRec.addQuery('fieldname', 'pass the filter value here'); //if it is new table of field then the field is empty , WHAT DO NOW
field will be empty on the record not on the table, I hope you will be passing the calculated value of any particular record, how will you get the record to set the value if you fo filer based upon the sys_id or any other parameter?