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

Thanks for your inputs..

Updated the UI actions that the sys_id of incident is stored in parent field of the request table.

 

Hence to autopopulate the ritm value in the custom field(u_requested_item), I have created an after insert update BR on sc_request table,

 

var reqitem = new GlideRecord("sc_req_item");
    reqitem.addQuery('request',current);
    reqitem.query();
    if(reqitem.next()) {
        var incident = new GlideRecord('incident');
        if (incident.get('sys_id', current.parent)) {
            incident.u_requested_number = reqitem;
            incident.update();
        }

}

 

This doesnt autopopulate the field on incident. Any help is appreciated.