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

Hi,

which field on current RITM record you want to update?

What's your requirement?

Regards
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

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

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

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

 

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