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

So can you share the code used in UI Action to understand how the linking is happening between Incident and Request.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

current.update();
var url;
var activeCatalogsCount = sn_sc.Catalog.getCatalogCount();
if (activeCatalogsCount === 1) {
url = 'sp?id=sc_category&catalog_id=e0d08b13c3330100c8b837659bba8fb4';
}
else {
url = 'sp?id=sc_category&catalog_id=e0d08b13c3330100c8b837659bba8fb4';
}


action.setRedirectURL(url);

 

It redirects to the SP page for raising request

So it is not creating Request Automatically but as to submit request manually from Portal.

 

So how to figure out that it happened through Incident? I am looking for that link that how system know that this Request was created through Incident? Is Parent field on REQ getting populated with Incident number?

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

You're right..Looks like we dn've a common link at all... what would you suggest in that case? 

Hi @Swetham 

 

What I can suggest it that when you redirect it to Portal with Catalog Item, you can have a hidden variable which can auto populate Incident Number or Incident Reference. Once Request is Submitted, you can map Parent field of REQ or RITM with that Incident record from hidden variable.

 

Then, you can create After BR on REQ or RITM where you have mapped Parent as Incident and there you can write code to map that number with your Custom Field on Incident record.

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023