Add change state tutorial: create new UI action

You must create a new UI action to display a button on a change request for the new Complete state.

Before you begin

Role required: admin

About this task

The new UI action must contain a condition that uses the state model script include to decide when the Complete button is displayed on the Change Request for. In this case, the Complete button will only be displayed when the change has reached the Implement state.

Procedure

  1. Open the Change Request form.
  2. Right click on the form header and go to Configure > UI Actions.
  3. Search for the existing Implement UI action and open this record.
  4. Right click on the form header and select the Insert and Stay option to create a duplicate record.
  5. Modify the following fields with new values.
    Field Values
    Name Enter Complete.
    Action name Enter state_model_move_to_complete.
    Hint Enter Progresses change to Complete state.
    Onclick Enter moveToComplete();.
    Condition Enter complete as shown:
    gs.hasRole('itil') && new ChangeRequestStateHandler(current).isNext("complete")
    .
    Script Update function, state name, and state value.
    function moveToComplete(){
                      var ga = new GlideAjax("ChangeRequestStateHandlerAjax");         
                      ga.addParam("sysparm_name", "getStateValue");         
                      ga.addParam("sysparm_state_name", "complete"); 
                      ga.getXMLAnswer(function(stateValue) {              
                          g_form.setValue("state", stateValue);              
                          gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_complete");         
                      });
              } 
              if (typeof window == 'undefined')   
                 setRedirect(); 
    
              function setRedirect() {   
                  current.update();   
                  action.setRedirectURL(current);
              }
    .
  6. Click Update to save the modifications.