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 Ankur,

Thanks for this, so this only calculates when we are having approvals. If there are no approvals, then the duration field will be blank.

I am having one more duration field where it calculates the total lifetime of the RITM (opened time till closed time)

These 2 fields will be on RITM table only, now here also I need to use after business rule and not to use current.update() .

I can achieve this with before update business rule, but as per our requirement , before should not be used.

So, here I need to write BR on RITM table and also glide record also to RITM Table? Please help me in high level approach how can I proceed

Hi,

2 scenarios

1) if RITM has approval then you can use logic I shared and if it doesn't have approval duration field will be blank. This is but obvious. -> BR on sysapproval

2) Other duration field you can anyhow populate by finding the difference of created and closure. -> Before Update BR on RITM

Now question is who informed you not to use before update BR on RITM and to use After BR only?

current.update() is not good practice.

You can query current record and update it using GlideRecord but why to do that?

Regards
Ankur

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

@Renu 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

@Renu 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

This is as per the best practice document from ServiceNow documentation.

https://docs.servicenow.com/bundle/sandiego-it-service-management/page/product/planning-and-policy/concept/request-management-architecture.html