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.

Copy assigned to and configuration item from Change request to Change Tasks

Justin Dirks1
Tera Expert

Hello everyone, 

 

I am having issues getting my business rule to run where I want to have the change request fields of Assigned to and Configuration Item to flood from the change request to the change tasks.  This is the script I am using. 

(function executeRule(current, previous /*null when async*/) {
    // Fetch the associated Change Request record
    var changeRequest = new GlideRecord('change_request');
    if (changeRequest.get(current.change_request)) {
        // Set the assigned_to and configuration_item fields on the Change Task
        current.assigned_to = changeRequest.assigned_to;
        current.configuration_item = changeRequest.configuration_item;
    }
})(current, previous);

Thank you for any help! 

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi @Justin Dirks1 your BR must be on change request table after insert or update 

Script:

 

var chgTask= new GlideRecord('change_task'); chgTask.addQuery('change_request', current.sys_id);

chgTask.query();

while (chgTask.next()) { // Copy the Assigned To and Configuration Item from Change Request to Change Task

chgTask.assigned_to =current.assigned_to;

chgTask.cmdb_ci = current.cmdb_ci; chgTask.update();

}

Regards
Harish

View solution in original post

2 REPLIES 2

Harish KM
Kilo Patron
Kilo Patron

Hi @Justin Dirks1 your BR must be on change request table after insert or update 

Script:

 

var chgTask= new GlideRecord('change_task'); chgTask.addQuery('change_request', current.sys_id);

chgTask.query();

while (chgTask.next()) { // Copy the Assigned To and Configuration Item from Change Request to Change Task

chgTask.assigned_to =current.assigned_to;

chgTask.cmdb_ci = current.cmdb_ci; chgTask.update();

}

Regards
Harish

That worked! Thank you so much!