How to Identify the Script Behind the Message Displayed When Applying a Template?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2025 03:28 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2025 05:26 AM
Step 1: Identify the Source of the Message
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.
Client Script:
The message is generated using the g_form.addInfoMessage() method in a client-side script. For example:
javascriptCopyg_form.addInfoMessage('Template applied successfully.');
Step 2: Locate the Script
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.
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:
textCopyNavigation: System UI → UI Actions → Search "name=Apply Template"
Check the Script field in the UI Action.
Step 3: Modify the Message
Edit the Client Script:
If the message is in a Client Script, edit the g_form.addInfoMessage() line.
Example:
javascriptCopy// Original g_form.addInfoMessage('Template applied successfully.'); // Modified g_form.addInfoMessage('Custom Template Applied!');
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:
Business Rules:
Navigate to System Definition → Business Rules.
Filter for rules on the sys_template table or your target table.
Script Includes:
Search for addInfoMessage in Script Includes (e.g., sys_script_include).