- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 10:47 PM
How to revert the change request state from schedule to new using revert to new button. Without altering the OOB script.
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 11:07 PM
Hi Deepthi,
You need to create UI Action which is server side and sample code below
UI Action Condition: visible when current state is schedule
// give here valid choice value for schedule
current.state == '5'
Script:
current.state = '2'; // give here the correct choice value for new
current.update();
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 02:02 AM
Hi Deepthi,
you can restart the workflow. you cannot revert workflow to any particular activity
script to restart workflow below which you add to UI action
var gr = new GlideRecord("change_request");
gr.addQuery("sys_id", current.sys_id);
gr.query();
if (gr.next()) {
new Workflow().restartWorkflow(gr);
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 11:53 PM
Hi Ankur,
But while updating the state we are getting "Invalid Update" error message.
Thank you in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2020 12:40 AM
Hi Deepthi,
check any before update BR which stops this
try this
current.state = '2'; // give here the correct choice value for new
current.setWorkflow(false);
current.update();
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2020 01:00 AM
Hi Deepti,
The best way is to modify the state model script of normal change type. In that way it will work in all the scenarios. And for that you don't have to create a new UI action or any other things you just need to include this code to the function in the script include:
Modify the script include name is :ChangeRequestStateModel_normal
in the scheduled function you have to just write one condition as below:
You need to include this script in the scheduled function
this piece handles the change in state from any state.
draft: {
moving: function() {
return this.toDraft_moving();
},
canMove: function() {
return this.toDraft_canMove();
}
},
Your update function will look like:
scheduled: {
nextState: [ "implement" ],
//Update ths to include revert to new
draft: {
moving: function() {
return this.toDraft_moving();
},
canMove: function() {
return this.toDraft_canMove();
}
},
implement: {
moving: function() {
return this.toImplement_moving();
},
canMove: function() {
return this.toImplement_canMove();
}
},
canceled: {
moving: function() {
return this.toCanceled_moving();
},
canMove: function() {
return this.toCanceled_canMove();
}
}
},
ServienNow itself says if any update on state flow we need to make so we have to make it in this script include so everywhere it will get applied.
Please mark helpful and correct.
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 05:33 AM
For all those that are still looking to find an answer to this issue, setting the state as "current.state()/update()" cannot function because the model states and their ChangeRequestStateModel_ script include does not allow it. Similarly, setting the script include alone without correlating the steps with the model states cannot work (and viceversa).
Final solution:
1. System Property "com.snc.change_management.change_model.manage_workflow" needs to be true.
2. Script include "ChangeRequestStateModel_emergency/normal/standard" needs to have the permission to move to the desired model states, so add the following for each model state you want to allow moving to new:
draft: {
moving: function() {
return this.toDraft_moving();
},
canMove: function() {
return this.toDraft_canMove();
}
},
3. Table "Model States" (sttrm_state.list) you will have all of the options available for each type of request. Group the results by Model and reorder by state to have a better view. For each state that you have added the access to "draft", you need to open the section record, and add the model state "new" within the list at the bottom of the form (called "Model State Transitions").
And that's all really...
Best regards,
Darius.