Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

BR to autopopulate RITM value on incident form

Swetham
Tera Contributor

I have created a custom field called REQUESTED ITEM(u_requested_item) in related records.

 

Now I have to autopopulate this field when a request is created from the incident.

 

I have used a Before BR:

Before - Insert&update

 

condition: current.sys_class_name == 'incident' && current.u_requested_item.nil()

Script: 

 

(function executeRule(current, previous /*null when async*/) {

if (current.sys_class_name == 'incident' && current.request_item.nil()) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.sys_id); 
ritm.query();

if (ritm.next()) {
current.request_item = ritm.sys_id;
}
}

})(current, previous);

 

For some reason its not populating.

Iam using UI action from incident to create a request.

 

Can anyone help on this?

 

Thanks in advance!

 

20 REPLIES 20

Anup Desai1
Mega Sage

Hi @Swetham ,

I think you have to replace current.request_item.nil() with current.u_requested_item.nil()
Please let me know if it's correct or not.

Please mark the answer correct/helpful based on Impact.
Regards, Anup

I have rectified that and it still doesn't work..

Hellow @Swetham ,

You are trying to fetch it and trigger condition is before insert -  request. So how it will get ritm with the request which is still not created. See below line from your code.

ritm.addQuery('request', current.sys_id);
 

I see it.. You have any suggestions?