Add a state to the state model

Mark Van Loock
Tera Guru

Hi, I'm struggling to add a state to the change request process. 

 

I am following this doc - 

https://docs.servicenow.com/bundle/utah-it-service-management/page/product/change-management/task/t_...

 

I want to add a "Completed" state between Review and Closed

 

I've done the following

1) From the change form, I've added the "Completed" state to the choices, giving it a value of 2.

2) Added "Completed" to the process flow

3) Created a "Complete" UI action with the following function - 

function moveToCompleted(){
var ga = new GlideAjax("ChangeRequestStateHandlerAjax");
ga.addParam("sysparm_name", "getStateValue");
ga.addParam("sysparm_state_name", "completed");
ga.getXMLAnswer(function(stateValue) {
g_form.setValue("state", stateValue);
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_completed");
});
}

 

Now this is where I think something may be amiss 

4) I've edited the script include - ChangeRequestStateHandler and added the following lines

ChangeRequestStateHandler.COMPLETED = "completed";

and further down in the script

this.STATE_NAMES["2"] = ChangeRequestStateHandler.COMPLETED;

 

 

5) I've then edited the script include - ChangeRequestStateModel_minor and added the following lines

review: {
nextState: [ "completed" ],

completed: {
moving: function() {
return this.toCompleted_moving();
},

canMove: function() {
return this.toCompleted_canMove();
}
},

},

 

 

 

When a (minor) change is at the review stage, I get the "Complete" button. If I click on it, the state changes to "Completed", however I get the bar along the top saying "Invalid update", and the state change is not saved.

 

Sorry for the lengthy post, but if anyone can give me some pointers, I'd greatly appreciate it.

1 REPLY 1

Dayini
Tera Contributor

Hi Mark,

I am no expert but thinking out loud maybe we need to add the transition in change state transitions for it to be valid. If it works out or you've found the solution please let me know. Thanks in advance !

Dayini_0-1738226851886.png

 

Regards,

Dayini