Community Alums
Not applicable

Hello Community,

 

While working on a client project, I encountered a challenge while trying to implement the requirement of reverting from the Scheduled state to New in a Normal change request using a UI action. Seeking assistance from the community, I discovered that this issue remains unresolved, with many developers encountering the same problem. They are often met with the error message "State Model for normal changes does not allow reverting change from Authorize state".

In this article, I'll guide you through resolving this issue and add UI action on the form context menu.

EZServiceNow_1-1710756500301.png

 

Follow these simple steps to streamline the process:

Steps:

  1. Update the Change Model

  2. Update the State Model

  3. Update the Script Include - ChangeRequestStateModel_normal

  4. Configure a UI Action

1. Update the Change Model

  • Navigate to Change > Administration > Change Models.
  • Locate and open the record named 'Normal' from the list.
  • Next, add a State transition under 'Scheduled' State as follows:

EZServiceNow_0-1710752092185.png

 

 

 

 

 

2. Update the State Mode:

  • Navigate to State Management > State Models.
  • From the list, open the record titled 'Example Change Request - Normal'.
  • Next, make the following update to the condition in the 'new' state transition (i.e., add OR condition 'State IS Scheduled')

EZServiceNow_1-1710752371234.png

 

3. Update the Script Include - 'ChangeRequestStateModel_normal'

The 'ChangeRequestStateModel_normal' is an out-of-the-box (OOTB) script include that manages the transition between states, determining which transitions are permissible.

 

Simply insert the following line of code into the scheduled block:

 

draft: {
            moving: function() {
                return this.toDraft_moving();
            },

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

 

 

For reference,

EZServiceNow_2-1710752890211.png

 

Note: Skipping the above 3 steps will result in the following error.

State Model for normal changes does not allow reverting change from Authorize state

 

4. Configure a UI Action

When it comes to configuring a UI Action for this requirement, there are two ways to consider.

Option 1: Utilize the out-of-the-box (OOTB) 'Revert to New' UI action:

This approach involves configuring a UI action by referencing the pre-built 'Revert to New' option. This method offers a straightforward solution for meeting your needs efficiently.

EZServiceNow_3-1710753025013.png

Ensure that you include the correct condition. In my scenario, I've utilized the following conditions:

 

(current.type == global.ChangeRequest.NORMAL && new global.ChangeRequest(current).isScheduled())

 

 

 Script:

 

revertToNew(current);
action.setRedirectURL(current);

function revertToNew(changeRequestGr) {
	var changeRequest = new global.ChangeRequest(changeRequestGr);
	if (!changeRequest.revertToNew())
		gs.addErrorMessage(gs.getMessage('State Model for {0} changes does not allow reverting change from {1} state', [changeRequest.getValue('type'), changeRequest.getDisplayValue('state')]));
}

 

 

Option 2] This is also done by using UI action. Please refer to this:

EZServiceNow_0-1710758366207.png

EZServiceNow_1-1710758418372.png

Script:

 

function moveToNew() {
	g_form.setValue("state", "-5");
	gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_new");
}

if (typeof window == 'undefined')
   setRedirect();

function setRedirect() {
    current.update();
    action.setRedirectURL(current);
}

 

Also, do not forget to fill in the Workspace and Required Roles tab info if necessary.

 

Please mark it as helpful and accept it as a solution if it helps you in any way.

Regards,
Prasad - "Here to help and empower."

Version history
Last update:
‎03-18-2024 03:51 AM
Updated by:
Community Alums
Contributors