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.

How to Identify the Script Behind the Message Displayed When Applying a Template?

KartheekG
Tera Contributor

When I apply a template to any record in ServiceNow, a message appears at the top of the form showing that the template has been applied. I want to know where this message comes from (Business Rule, UI Action, Script Include, etc.) so I can modify or use it for my use case.

How can I find the exact script or logic that triggers this message?

1 REPLY 1

Murtaza Saify
Tera Contributor

Step 1: Identify the Source of the Message

  1. UI Action:

    • Navigate to System UI → UI Actions.

    • Search for UI Actions on the sys_template table (the table for templates).

    • Look for a UI Action named something like Apply Template or Apply Template to Record.

    • Open the UI Action and check its Client Script or OnClick field.

  2. Client Script:

    • The message is generated using the g_form.addInfoMessage() method in a client-side script. For example:

      javascript
      Copy
      g_form.addInfoMessage('Template applied successfully.');

Step 2: Locate the Script

  1. For Templates on a Specific Table:

    • If the template is applied to a custom table (e.g., incident), check the Client Scripts or UI Actions on that table.

    • Go to the table’s form → Right-click the header → Configure → UI Actions.

  2. Global Template Application:

    • The default template logic is often in the global UI Action Apply Template (sys_ui_action with name "Apply Template").

    • To find it:

      text
      Copy
      Navigation: System UI → UI Actions → Search "name=Apply Template"
    • Check the Script field in the UI Action.


Step 3: Modify the Message

  1. Edit the Client Script:

    • If the message is in a Client Script, edit the g_form.addInfoMessage() line.

    • Example:

      javascript
      Copy
      // Original
      g_form.addInfoMessage('Template applied successfully.');
      // Modified
      g_form.addInfoMessage('Custom Template Applied!');
  2. Override with a New UI Action (Recommended for Customization):

    • Clone the existing UI Action and modify the message in the clone.

    • Set Order to a higher value (e.g., 100) to override the default action.


Step 4: Verify Using Background Scripts

If the message is server-side (rare), check Business Rules or Script Includes:

  1. Business Rules:

    • Navigate to System Definition → Business Rules.

    • Filter for rules on the sys_template table or your target table.

  2. Script Includes:

    • Search for addInfoMessage in Script Includes (e.g., sys_script_include).