Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Dynamic State Progression via UI Action Button (Without Workflow or Flow Designer)

muneermajeed
Tera Contributor

Hey SN Community! 
I recently created a UI Action button that updates a custom field (status) to the next logical state each time the button is clicked — kind of like a manual progression engine.

 Objective:
When a user clicks the button:

  • If the current status is "new" → it becomes "retried"

  • "retried" → "inprogress"

  • "inprogress" → "resolved"

  • After "resolved": shows error message "Last status"

This works without using any Flow Designer or Workflow logic — just simple JavaScript in the UI Action.

 Use Case:

// keys and values 
    var nextStates = {
        'new': 'retried', 
        'retried': 'inprogress',   
        'inprogress': 'resolved'     
    };
    
    if (nextStates[current.u_status]) {
        current.u_status = nextStates[current.u_status];
        current.update();
        action.setRedirectURL(current);
    } else {
        gs.addErrorMessage("Last status");
    }
// }


Useful for custom status fields where you want to give users a quick way to move the record through a defined sequence.

0 REPLIES 0