How to copy the last CTASK close code to Change request while close the CR.

VIKAS MISHRA
Tera Contributor

For the change request, the last task is change review task and when someone closes this task then Change request will auto closed as workflow gets completed after this CTASK activity.

We want that when this last task gets closed at the same time the close notes of this task should be copied to Change request notes section.

Please suggest that how its possible 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@VIKAS MISHRA 

you can handle the same in your workflow if you are using that.

Have a run script to query the CTASK with this CHG and pick the latest one, pick the notes and put in CHG

something like this

    // Add your code here
    var gr = new GlideRecord("change_task");
    gr.orderByDesc('sys_created_on'); // pick the latest one
    gr.addQuery("change_request", current.sys_id);
    gr.setLimit(1);
    gr.query();
    if (gr.next()) {
        current.close_notes = gr.close_notes;
        current.update();
    }

OR Another way

Have after update business rule on change_task with condition as Task closes

Use similar script above and check if the task which is getting closed is the last one, if yes then copy

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

@Ankur Bawiskar

 

I have created after update BR but its not working.

I checked and found that when we are querying the  change record, instead of change request SYS_ID its picking up the sys if of last change task.

@VIKAS MISHRA 

sorry this line is updated now

gr.addQuery("change_request", current.change_request);

Use the below and test

 // Add your code here
    var gr = new GlideRecord("change_task");
    gr.orderByDesc('sys_created_on'); // pick the latest one
    gr.addQuery("change_request", current.change_request);
    gr.setLimit(1);
    gr.query();
    if (gr.next()) {
        current.close_notes = gr.close_notes;
        current.update();
    }

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

@VIKAS MISHRA 

Hope you are doing good.

Did my reply answer your question?

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