- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 05:45 AM
Dear Expert
I have a requirement to move the change state from scheduled to New if user click on the button "Revert to New" and change state will move to new and whatever impacted service was there previously in the change ticket will removed from the related list. Also if any task is in closed state, then that should be open . I am not sure how to start with the requirement and what type of script i have to write here. I found a UI action "Revert to New" but this is appearing only in Assess state and it is only moving the change ticket state from Assess to New not from Authorize to new or scheduled to new.
Can some please help with the logic and if possible script as well.
Thank in advanced
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 10:12 AM
Hi Prasnajeet,
If you are looking to implement this change for normal changes then yes you are looking at the right ChangeRequestStateModel script. You will also find scripts that end with _standard, _emergency, etc.
As far as the rollbackChange function is concerned, the way that I have that set up it needs to be part of a script include. The name of the script include is irrelevant. Just change the line
var changeFunctions = new IntegraChangeScripts();
To have the name of your script instead of IntegraChangeScripts (don't forget to include the parentheses after the name). If you are putting the function into an existing script include make sure that the Client Callable box for that script is checked. I set up a demo script include so that you can see how things should look.
var DemoScriptInclude = Class.create();
DemoScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
rollbackChange: function(theChangeNumber) {
var theChange = new GlideRecord("change_request");
theChange.get("number", theChangeNumber);
theChange.setValue("state", -5);
theChange.update();
var gLock = new GlideRecordLock(theChange);
gLock.setSpinWait(50);
if (gLock.get()) {
new Workflow().restartWorkflow(theChange, false);
}
var theApprovals = new GlideRecord("sysapproval_approver");
theApprovals.addQuery("sysapproval", theChange.sys_id);
theApprovals.query();
while (theApprovals.next()) {
theApprovals.setValue("state", "not_required");
theApprovals.update();
}
gLock.setSpinWait(50);
if (gLock.get()) {
new Workflow().restartWorkflow(theChange, false);
}
},
type: 'DemoScriptInclude'
});
One other thing to be sure to do is have the comma after the closing curly brace at the end of the function. If you leave that out and don't know to look for it, debugging will drive you crazy.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 06:04 AM
Hi Prasnajeet,
The error that you are getting is the ServiceNow way of saying that you haven't set up Scheduled to New as an allowable move in the script include ChangeRequestStateModel_standard.
As far as limiting the states under which the UI action is visible, you need to update the Condition box in the UI Action definition to include:
current.state == -4 || current.state == -3 || current.state == -2
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 06:04 AM
Hi Prasnajeet,
The error that you are getting is the ServiceNow way of saying that you haven't set up Scheduled to New as an allowable move in the script include ChangeRequestStateModel_standard.
As far as limiting the states under which the UI action is visible, you need to update the Condition box in the UI Action definition to include:
current.state == -4 || current.state == -3 || current.state == -2
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 06:24 AM
Hello @Prasnajeet1 ,
Hope you are doing well!
This might help you 🙂
Solution: Revert to New from Scheduled State in Change Request