populate change task fields from change request

Scotty88
Tera Contributor

I am trying to create a BR to do the following however can't get this to work, I have tried both before and after insert (see script below), all I am trying to do is:

 When a change task is created from a change request the following fields on the change tasks are copied from the parent change:

- The Change Number of the parent change is copied to the Short Description of the Change Task

- The Planned start date and Planned end date of the parent change are copied to the Planned start date and Planned end date of the change task

 

 

 

(function executeRule(current, gsn, gs) {

    if (!current.change_request) {
        return;
    }

    // Load parent change request
    var parentChange = new GlideRecord('change_request');
    if (parentChange.get(current.change_request)) {

        // Load current task again in writeable mode
        var task = new GlideRecord('change_task');
        if (task.get(current.sys_id)) {

            // Populate short_description if empty
            if (!task.short_description) {
                task.short_description = parentChange.number;
            }

            // Populate planned_start_date if start_date exists
            if (!task.planned_start_date && parentChange.start_date) {
                task.planned_start_date = parentChange.start_date;
            }

            // Populate planned_end_date if end_date exists
            if (!task.planned_end_date && parentChange.end_date) {
                task.planned_end_date = parentChange.end_date;
            }

            task.update();
        }
    }

})(current, gsn, gs);
8 REPLIES 8

mohdarbaz
Kilo Guru

Hi @Scotty88 ,

 

Try this

Table: Change Task

Before

Insert

 

(function executeRule(current, previous /*null when async*/) {
    // Get the parent change request record
    var changeRequest = new GlideRecord('change_request');
    if (changeRequest.get(current.change_request)) {
        // Check if Change Number exists and copy it to the Short Description of the Change Task
        if (changeRequest.number) {
            current.short_description = changeRequest.number;
        }
       
        // Check if Planned Start Date exists and copy it to the Planned Start Date of the Change Task
        if (changeRequest.planned_start_date) {
            current.planned_start_date = changeRequest.planned_start_date;
        }
       
        // Check if Planned End Date exists and copy it to the Planned End Date of the Change Task
        if (changeRequest.planned_end_date) {
            current.planned_end_date = changeRequest.planned_end_date;
        }
    }
})(current, previous);

 

If my response helped, please mark it correct/helpful and close the thread so that it benefits future readers.

 

Regards,

Mohd Arbaz.

@Scotty88 , try this alternative, it worked. I had just tested.

Ankur Bawiskar
Tera Patron
Tera Patron

@Scotty88 

no scripting required, simply use Actions tab in Before Insert Business rule

See below

You need to click on Show Related Fields -> Select Change Request -> Then Select the actual field to pick from CHG

change task set values.gif

AnkurBawiskar_0-1746589290621.png

 

AnkurBawiskar_1-1746589302399.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yeah i previously tried that however does not work, the fields are still blank when you create a change task (from the change task related list on the parent change)