Business rule to align start and end dates of change with change tasks

lmao
Tera Contributor

hello dear community,

 

im trying to create a BR which will trigger when the start or end date of a change changes.

It then should fill the start and/or end date of the related change task(s).

 

It seemed at first like a quick fix but for some reason the BR wont trigger. I have tried to use a script and the script debugger but although i trigger it, the BR isnt running. I have tried to change the order and the "when" but nothing seems to help. 

Its the same in my PDI, i think there is something i miss.

 

For help and suggestions i will be very grateful,

 

 

 

CHGdate.png

CHTASKdate.png

BR.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@lmao 

you can use flow or you can use after update BR on change_request table

Condition: Start Date Changes OR End Date Changes

Script:

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

    // Add your code here
    var gr = new GlideRecord("change_task");
    gr.addQuery("change_request", current.getUniqueValue());
    gr.query();
    while (gr.next()) {
        gr.planned_start_date = current.start_date;
        gr.planned_end_date = current.end_date;
        gr.update();
    }

})(current, previous);

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

View solution in original post

7 REPLIES 7

Mark Manders
Mega Patron

Your trigger is on the wrong table. You need to trigger it from the chang table itself, not dotwalking to it.

Then you can do a query to the change task and update the fields.

You could also do this through a flow, which will eliminate the need for a script. You can just do a lookup and drag and drop the fields.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

thank you for your answer. i have created a flow now with the "look up records". but it wont find any records to update. My approach was: look up records (CTASKS) - change_request is same as "number" field in the trigger. Did i apply it wrong?

 

lmao_0-1738065877186.png

 

lmao
Tera Contributor

this is the output of the test. 

 

Thank you in advance for your help,

lmao_0-1738066146567.png

 

@lmao 

in the Lookup you should select the sysId and not change number for the Trigger

Change Request field on Change task is a reference field

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