Based on planned start date and time Change phase should move from schedule to implement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 05:39 AM
Hi Experts,
I don't have much knowledge on scripting.
We have a requirement for change module in which based on planned start date and time phase should be automatically moved from schedule to implement.
In order to achieve this, I need build a script logic in schedule UI action, but I dont know much about script logic can someone help to build this script logic and let me know if my understanding is correct or do you suggest any other way to achieve this.
Please advice!
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 05:59 AM
Hi,
You can write a BR after the update and trigger a custom event.
For this, first, you should create the event. Go to System Policy-> Events -> Registry and create new event.
Then in the BR, write like this
gs.eventQueue('your event name', current, current.sys_id); //this will trigger the event and passes the change request object and sys_id.
Then write a script action (System policy-> Script actions). Create new and give the name of the script and select your event name. Make active true.
In the script field, write the code
var gr=new GlideRecord("change_request");
gr.addQuery("sys_id",event.parm1); //parm1 contains the sys_id of the hcnage rquest.
gr.query();
if(gr.next()) {
if(gr.getValue("start_date")=="yourvalue") {
//change the state of the chnage reuqest
gr.state=-1;
gr.update();
}
}
PS: The script need to be change with the actual field names and values as per your DB structure.
Mark the comment as a correct answer and helpful if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 10:29 AM
Hi,
Thanks for the reply.
Cant I do something with existing UI action for schedule instead of BR without creating custom event.
Please help me to understand the flow doesn't this go through with UI action or should we approach workflow to achieve this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 10:35 AM
This is possible OOB with state model for change_request table.
You do not need to write any code for configuring state model.
Please see below for more details on state model
https://docs.servicenow.com/bundle/london-it-service-management/page/product/change-management/concept/c_ChangeStateModel.html
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 02:08 AM
Just implemented this for my current customer. It works fine!
Please mark helpfull when it does! thanks
Final script I used:
var grCR = new GlideRecord('change_request');
//Active scheduled Changes with a Start date till 1 Hour from now
grCR.addEncodedQuery('active=true^state=-2^start_date<=javascript:gs.hoursAgo(-1)');
grCR.query();
while (grCR.next()) {
grCR.state = -1; //Implement state
grCR.update();
gs.log('Automatically move scheduled Change ' + grCR.number + ' to Implement as it almost reaches Planned start', 'Scheduled script: move scheduled Changes to Implement');
}
Scheduled script Execution:
Regards, Peter