- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 04:32 AM
Hi ,
I am writing an After Business rule on RITM table, where in as per requirement I also need to glide record to the same RITM table in that Business rule, Is it possible to call glide record of same table.
In the After Business rule, as current.update() should not be used, we were asked to use gr.update(); to satisfy the requirement.
Please guide me how to call the same table using glide record.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 07:29 AM
Hi,
If RITM has no approval then why to calculate the difference?
You should be concerned about only RITMs which have approval
After update BR on sysapproval_approver
Condition: current.source_table == 'sc_req_item'
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritm = new GlideRecord('sc_req_item');
ritm.get(current.sysapproval);
var opened = new GlideDateTime(ritm.sys_created_on);
var nowTime = new GlideDateTime();
var duration = GlideDateTime.subtract(opened, nowTime);
ritm.u_duration = duration;
ritm.update();
})(current, previous);
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 04:35 AM
Hi Renu,
yes I think you can do it like you normally do for other tables.
What is your requirement?
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 04:41 AM
Hi Renu,
Yes you can call GlideRecord on the same table once again and instead of using gr.update to update the record, you can use:-
current.setWorkflow(false);
current.update();
current.setWorkflow(true);
By setting setWorkflow false other business rules wouldn't be triggered.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 04:49 AM
You can use gr.update(), that should not be an issue, but make sure, this update() statement should not be triggered for your current record
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 04:58 AM
Hi Aman,
var number= current.number;
var gr = new GlideRecord('sc_req_item');
var sysid= current.sys_id;
gr.addQuery(number, sysid);
gr.query();
gs.log("ritm approval sys id query" +gr.getRowCount());
if(gr.next())
{
var start = new GlideDateTime(current.opened_at); //opened time
var end = new GlideDateTime(current.approval_set); //ritm approved time
gs.log("ritm approval " + start);
gs.log("ritm approval " + end);
var dc = new DurationCalculator();
var sch = gs.getProperty('Schedule');
dc.setSchedule(sch); //Business Hours 8 AM - 5 PM (Mon to Fri)
var time = dc.calcScheduleDuration(start, end); // time would be in seconds
var durationMS = time * 1000;
var result = new GlideDuration(durationMS);
var duration = result.getDisplayValue();
gr.update();
}
})(current, previous);
in the log gr.getrowcount(), it is returning the RITMs count, but instead it should only return a single RITM that I am searching correct.
Please suggest changes in the script