Category: Scenario-Based Questions PART 33
Updated on: August 12, 2025  |  0

Scenario-Based Questions PART 33

🎓 Scenario-Based Question

 

📌 Use Case: Restrict Parent Incident Closure Until All Child Incidents Are Closed

This use case ensures that a parent incident in ServiceNow cannot be closed until all its child incidents are in the closed state. We’ll use a Business Rule to enforce this rule.


🛠 Steps to Implement:

  1. Create a Business Rule
    • Name: CloseChildBeforeParentINC
    • Table: incident
    • Active ✅
    • Advanced ✅
    • When: Before Update
  2. Add the Script
    (function executeRule(current, previous /*null when async*/) {
    
        var inc = new GlideRecord('incident');
        inc.addQuery('parent_incident', current.sys_id);
        inc.query();
    
        while (inc.next()) {
            if (inc.state == '7') { // 7 = Closed
                gs.addInfoMessage("✅ All Child INCs are CLOSED.");
                current.setAbortAction(false);
            } else {
                gs.addErrorMessage("❌ Child INCs are not CLOSED yet. Please close them first.");
                current.setAbortAction(true);
            }
        }
    
    })(current, previous);
          
  3. Test the Rule
    • Create a parent incident with one or more child incidents.
    • Ensure at least one child is still open.
    • Try closing the parent — you should see an error message.
    • Once all children are closed, you can close the parent successfully.

💡 Pro Tips:

  • You can change inc.state == '7' to match your organization’s custom closed state value.
  • Using current.setAbortAction(true) stops the update process if the rule fails.
  • Info and error messages are visible only to the current logged-in user performing the update.

Comments

No comments yet.


Log in to post a comment