Business Rule to close universal requests when the primary ticket is closed

Bret Smith
Giga Guru

I need a business rule to close universal requests when the primary ticket is closed

5 REPLIES 5

Astik Thombare
Tera Sage

Hi @Bret Smith ,

 

To create a business rule in ServiceNow that automatically closes universal requests when the primary ticket is closed, follow these steps:

  1. Identify the relationship: Ensure you know how the universal requests are related to the primary tickets. Typically, this is done via a reference field or some linking mechanism.
  2. Create the Business Rule: The business rule will be triggered when the primary ticket is closed and will find and close the related universal requests.

Steps to Create the Business Rule

  1. Navigate to: System Definition > Business Rules.
  2. Click New to create a new business rule.
  3. Configure the Business Rule with the following details:
    • When: After
    • Insert: False (uncheck)
    • Update: True (check)
    • Delete: False (uncheck)
    • Query: False (uncheck)
    • Update: Check
    • Name: Close Universal Requests on Primary Ticket Closure
    • Table: The table of your primary ticket (e.g., incident, change_request, etc.)
    • Advanced: Check this box to enable scripting.
    • When to Run:
    • Condition: current.state.changesTo(CLOSED_STATE) (replace CLOSED_STATE with the actual value representing the closed state for your primary ticket)

4.Script: In the "Advanced" tab, add the following script:

 

(function executeRule(current, previous /*null when async*/) {
    // Replace 'primary_ticket_field' with the actual field that links the universal request to the primary ticket
    var gr = new GlideRecord('universal_request');
    gr.addQuery('primary_ticket_field', current.sys_id);
    gr.addQuery('state', '!=', 'closed'); // Assuming 'closed' is the state name or use appropriate state value
    gr.query();
    while (gr.next()) {
        gr.state = 'closed'; // Set the state to closed or the appropriate closed state value
        gr.update();
    }
})(current, previous);

Explanation:

  • Trigger on Update: The business rule is triggered when the primary ticket is updated.
  • Condition: It checks if the state of the primary ticket has changed to the closed state.
  • Script:
    • It creates a GlideRecord for the universal request table.
    • It queries all universal requests linked to the primary ticket that are not already closed.
    • It sets the state of each matching universal request to closed and updates the record.

Customize as Needed:

  • primary_ticket_field: Replace this with the actual field that links the universal request to the primary ticket.
  • 'universal_request': Replace this with the actual table name for the universal requests if different.
  • 'closed': Replace with the appropriate closed state value for the universal request.

This approach ensures that whenever the primary ticket is closed, all related universal requests are also closed automatically

 

If you find my response helpful, please mark it as helpful 👍. If it resolves your issue, please mark it as correct

 

Thanks,

Astik

 

How do I fix (close) the Universal Requests that already have the primary ticket closed? 

One time run of some fix script

Abhijit4
Mega Sage

This can simply be achieved with State Mapping records which is available OOTB for UR.

 

More details : UR State Mapping 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

How do I close Universal Requests where the corresponding Request is already closed?

 

What are the details for a fix script to do that