Call Glide record of table (RITM) in the Business rule which is written on same table (RITM)

Renu9
Tera Contributor

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.

1 ACCEPTED SOLUTION

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

19 REPLIES 19

Yousaf
Giga Sage

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.***

kunal20
Kilo Guru

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.

Aman Kumar S
Kilo Patron

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

Best Regards
Aman Kumar

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