The Zurich release has arrived! Interested in new features and functionalities? Click here for more

update the list type field on a parent incident with multiple child incidents with unique values in

Richard Tyler
Tera Expert

I need to update a parent incident list type field with values from multiple child incidents. Each child incident is meant to pass a unique value to the parent incident to aggregate the vlaue in the parent incident. 

My script updates the parent incident field, but when a new chield incident is related, the value of the field changes to the value of the newly related child incident. (replaces the value, not add)

How do i fix this? I am using a business rule.

 

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

// Add your code here
    var parentincident = new GlideRecord("incident");
    parentincident.addQuery('sys_id', current.parent_incident);
    parentincident.query();
    if (parentincident.next()) {
        parentincident.u_user_location=current.u_user_location;
       
        parentincident.update();
    }

})(current, previous);
2 REPLIES 2

Unique45
Mega Sage

Hello @Richard Tyler ,

Below code will fix your issue:

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

// Add your code here
    var parentincident = new GlideRecord("incident");
    parentincident.addQuery('sys_id', current.parent_incident);
    parentincident.query();
    if (parentincident.next()) {
            if((parentincident.u_user_location)  == ''){
            parentincident.u_user_location =current.u_user_location;
       }else{
             parentincident.u_user_location += ','+current.u_user_location;
       }
       parentincident.update();
    }

})(current, previous);

 

Please mark correct/helpful if this helps you!

Mani A
Tera Guru

Change the line after if 

parentincident.u_user_location+= ','+current.u_user_location;