- 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 06:41 AM
Hi,
which field on current RITM record you want to update?
What's your requirement?
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 06:40 AM
Hi,
why to query same table and same record?
Why not use Before update/Insert BR and perform the logic and you need not use current.update()?
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 06:46 AM
Hi,
do you want to populate the difference between RITM created time and the time when RITM is approved and populate it in some duration field?
If yes then you can use after update on sysapproval_approver table and do that
No need for BR on RITM table
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 07:07 AM
Hi Ankur,
Yes, I want to populate the difference between RITM created time and the time when RITM is approved and populate it in some duration field
Even tried with sysapproval_approver table but for few RITMs there is no approvers. For those RITMs there will be no record created in sysapproval_Approver table. Hence this is not satisfying our requirement
Before BR also did not work for us, because approval_set value is being set after hitting the server. Hence, we should go with after Business rule and also current.update() should not be used as per company's requirement.
Please guide me in this
- 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