The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Mastering UI Actions in ServiceNow – From Clicks to Custom Logic 🚀

Nilay_Potdukhe
Tera Contributor

🛠What Is a UI Action in ServiceNow?
A UI Action is a powerful customization tool that adds buttons, links, or context menu items to forms and lists giving users quick access to actions that improve efficiency and workflow.

UI Actions can be configured to run on the client side, server side, or both, depending on the use case. They’re commonly used to trigger scripts, navigate to other pages, or perform record operations like approvals, rejections, or custom logic.

🔍 UI Actions can be triggered from:
• Form buttons (e.g., "Resolve", "Approve")
• List buttons (e.g., "Delete Selected")
• Context menu items (right-click options)
• Form links (inline actions)

💡 Client vs Server Execution:
• Client-side UI Actions use g_form and g_user to interact with the form directly
• Server-side UI Actions use GlideRecord and server APIs to manipulate data securely
• You can also use isClient and isServer flags to control execution scope

UI Actions are stored in the sys_ui_action table in ServiceNow.

Whether you're streamlining approvals or launching custom workflows, UI Actions help make ServiceNow more interactive and user-friendly.

  • Use Cases of UI Action: -
  1. Add a custom button to the Incident form that displays the count of incidents from the same assignment group. This button should only be visible to admin users and only when the incident state is New, In Progress, or On Hold.
    • Steps to Implement UI Action
  1. Navigate to: All > System definition > UI Action
  2. Configure the fields:
    • Name: count of incidents from same assignment group
    • Table: Incident
    • Order: 100
    • Active: True
    • Show insert: True
    • Show Update: True
    • Form Button: True
    • Condition: ((current.state == 1 || current.state == 2 || current.state == 3) && gs.hasRole("admin"))
  1. Script: -

var gr = new GlideRecord('incident');

gr.addQuery('assignment_group',current.assignment_group);

gr.addActiveQuery();

gr.query();

action.setRedirectURL(current);

gs.addInfoMessage("Total number of open incident"+current.assignment_group.name+'count'+gr.getRowCount());

2. Add a custom button to the Incident form that, when clicked, shows the count of past incidents logged by the same user. This button should be visible only to admin users.

  • Steps to Implement UI Action
  1. Navigate to: All > System definition > UI Action
  2. Configure the fields:
    • Name: count of incidents from same user
    • Table: Incident
    • Order: 100
    • Active: True
    • Show insert: True
    • Show Update: True
    • Form Button: True
    • Condition: gs.hasRole("admin")
  1. Script: -

var gr = new GlideRecord('incident');

gr.addQuery('caller_id',current.caller_id);

gr.addActiveQuery();

gr.query();

action.setRedirectURL(current);

gs.addInfoMessage("Total number of open incident"+current.caller_id.name+'count'+gr.getRowCount());

3.Add a custom button to the Incident form that, when clicked by an admin user, automatically resolves the incident and sets the correct resolution code based on predefined logic.

  • Steps to Implement UI Action
  1. Navigate to: All > System definition > UI Action
  2. Configure the fields:
    • Name: Resolve incident
    • Table: Incident
    • Order: 100
    • Active: True
    • Show insert: True
    • Show Update: True
    • Form Button: True
    • Condition: ((current.state == 1 || current.state == 2 ) && gs.hasRole("admin"))
  1. Script: -

current.state = 7;

current.close_code = 'Resolved by caller';

current.close_notes = 'closed via ui action';

current.update();

action.setRedirectURL(current);

4.Button on incident form to assign the ticket to current logged in user.

  • Steps to Implement UI Action
  1. Navigate to: All > System definition > UI Action
  2. Configure the fields:
    • Name: Assigning inc to me  
    • Table: Incident
    • Order: 100
    • Active: True
    • Show insert: True
    • Show Update: True
    • Client: True
    • List v2 Compatible: True
    • Form Button: True
    • OnClick: autoAssignment()
  1. Script: -

function autoAssignment(){

var us = g_user.userID;

g_form.setValue('assigned_to',user);

g_form.setValue('work_notes','assigning to me');

g_form.save();

}

5.UI action on incident record to create 3 incident tasks automatically with same incident.

  • Steps to Implement UI Action
  1. Navigate to: All > System definition > UI Action
  2. Configure the fields:
    • Name: Incident task creation  
    • Table: Incident
    • Order: 100
    • Active: True
    • Action name: create_inc_task
    • Show Update: True
    • Form Button: True
  1. Script: -

var shordes = ['Incident task 1','Incident task 2','Incident Task 3'];

for(i=0; i<shordes.length;i++)

{

    var gr = new GlideRecord('incident_task');

    gr.initialize();

    gr.short_description = shordes[i];

    gr.incident=current.sys_id;

    gr.insert();

}

action.setRedirectURL(current);

6.Create UI action to open Problem form from incident record.

  • Steps to Implement UI Action
  1. Navigate to: All > System definition > UI Action
  2. Configure the fields:
    • Name: Open Problem form  
    • Table: Incident
    • Order: 100
    • Active: True
    • Action name: open_problem_form
    • Show Update: True
    • Show Insert: True
    • Form Button: True
  1. Script: -

var url = '/problem.do?sys_id=-1';

action.setRedirectURL(url);

1 REPLY 1

RobertW50103489
Mega Contributor

Thank you for this