How to copy Fields from Change Request to Change Task?

Supriya P
Tera Contributor

Hi,

We have configured change request workflows where after closing one change task second task gets created.

I have applied business rule on change request table but it is only working on first change task. How to populate values on second change task?

Table : change_request (After ---> Update)

Condition : State changes to Implement

Script : 

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

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

while (task_gr.next()) {
task_gr.planned_start_date = current.start_date;
task_gr.planned_end_date = current.end_date;
task_gr.assignment_group = current.assignment_group;
task_gr.cmdb_ci = current.cmdb_ci;

task_gr.update();
}

})(current, previous);

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Is the CHG getting updated while creating 2nd task?

why not use before insert BR on change_task and set the fields during insertion itself

current.planned_start_date = current.change_request.start_date;
current.planned_end_date = current.current.end_date;
current.assignment_group = current.current.assignment_group;
current.cmdb_ci = current.current.cmdb_ci;

Regards
Ankur

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

Hi Ankur,

Thank you.

Yes Change will update while creating second task.

 

Hi,

then in that case it might not be finding the latest change_task

Regards
Ankur

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

What is the solution for this?