0

Using a Client Script

  1. Create a Client Script:
    • Navigate to System Definition > Client Scripts.
    • Click on New to create a new Client Script.
    • Set the Table to incident and Type to onLoad.
  2. Add Script Code:
    • Use the following script to check if the incident has any child incidents and display a warning message:

(function() {
    // Create a GlideRecord object for the Incident table
    var gr = new GlideRecord('incident');
    // Query for child incidents where the parent is the current record
    gr.addQuery('parent', current.sys_id);
    gr.query();
     // Check if any child incidents are found
    if (gr.hasNext()) {
        // Show a warning message
        g_form.addInfoMessage('This incident has one or more child incidents.');
    }
})();

Explanation:

  • GlideRecord('incident'): Creates a GlideRecord object to query the Incident table.
  • addQuery('parent', current.sys_id): Filters records where the parent field matches the current incident's sys_id.
  • hasNext(): Checks if there are any child incidents.
  • g_form.addInfoMessage(): Displays an informational message on the form.

Additional Considerations:

  • Ensure that the 'parent' field in your Incident table is correctly configured to link child incidents.
  • Adjust message type: If you want a more prominent warning, you could use g_form.addErrorMessage() instead of addInfoMessage(), but be cautious with error messages as they might imply more critical issues.
To display a warning message on an Incident record/form in ServiceNow if it has a child incident
Working Code Asked question September 17, 2024