Business Rule to close universal requests when the primary ticket is closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 12:20 PM
I need a business rule to close universal requests when the primary ticket is closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 11:19 PM
Hi @Bret Smith ,
To create a business rule in ServiceNow that automatically closes universal requests when the primary ticket is closed, follow these steps:
- 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.
- 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
- Navigate to: System Definition > Business Rules.
- Click New to create a new business rule.
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 07:57 AM
How do I fix (close) the Universal Requests that already have the primary ticket closed?
One time run of some fix script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 11:58 AM
This can simply be achieved with State Mapping records which is available OOTB for UR.
More details : UR State Mapping
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 04:11 PM
How do I close Universal Requests where the corresponding Request is already closed?
What are the details for a fix script to do that