- 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-16-2017 04:56 PM
is u_total_budget a SUM of all the second field from incident table? if yes, let's see if this helps.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var cal = 0;
var gr = new GlideRecord('incident');
gr.addQuery('u_portfolio', current.u_portfolio);
gr.query();
while(gr.next())
cal = parseFloat(cal) + parseFloat(gr.getValue('u_second').substring(4).replace(',', ''));
var bRec = new GlideRecord('u_sales_lead');
if(bRec.get('sys_id', current.u_portfolio)){
bRec.u_reaming_budget = parseFloat(cal) - parseFloat(current.u_total_budget.substring(4).replace(',', ''));
bRec.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 09:54 PM
Hi Shishir,
I am waiting for your reply
gr.addQuery('u_portfolio', current.u_portfolio);
Not working...
Here we have relation between incident and sales tables
If you see the sales table- there are 2 records are there
1.cisco
2.unisco
Sales table is reference table to portfolio field in incident.
So based on portfolio value calculate total sum from list of records and get that value , subtract total sum value from
Sales table from related recods
Ex: sales table have 2-records
1.cisco
2. Unisco
In incident table
Portfolio :Cisco related total records 4, get total 4 records sum value and subtraction from sales table field- Total Budget
As the same way
Portfolio: unisco related total records 5
Note: if you want more details I will explain.... please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 10:52 PM
Hi Shisir,
As you suggested , i have mentioned your script , but not working.
var cal = 0;
var gr = new GlideRecord('incident');
gr.addQuery('u_portfolio', current.u_portfolio);
gr.query();
while(gr.next())
cal = parseFloat(cal) + parseFloat(gr.getValue('u_second').substring(4).replace(',', ''));
var bRec = new GlideRecord('u_sales');
if(bRec.get('sys_id', current.u_portfolio)){
bRec.u_remaing_fund = parseFloat(cal) - parseFloat(current.u_total_fund.substring(4).replace(',', ''));
bRec.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2017 05:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 03:41 AM
Hi,
Can you please let me know how and where to use these scripts.
Completely new to scripting in servicenow and I have same requirement as above.
Thanks in Advance