|
| 1 | +### Prompt for Creating a Business Rule to Auto-Close Resolved Incidents |
| 2 | + |
| 3 | +**Prompt:** Develop a Business Rule that automatically changes the state of incidents to "Closed" if they have been in the "Resolved" state for more than 7 days. This will help in maintaining a clean incident table and ensuring timely closure of resolved incidents. |
| 4 | + |
| 5 | +**Structure:** Outline the steps to create the Business Rule, including the conditions and script logic for closing incidents. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +### Expected Output: |
| 10 | + |
| 11 | +1. **Navigate to Business Rules:** |
| 12 | + - Go to **System Definition > Business Rules** in ServiceNow. |
| 13 | + - Click on **New** to create a new Business Rule. |
| 14 | + |
| 15 | +2. **Configure Business Rule Properties:** |
| 16 | + - **Name:** Auto-Close Resolved Incidents |
| 17 | + - **Table:** Incident [incident] |
| 18 | + - **Active:** True |
| 19 | + - **Advanced:** True (to write a script) |
| 20 | + |
| 21 | +3. **Set When to Run:** |
| 22 | + - **When:** After (to ensure the rule runs after the record has been saved) |
| 23 | + - **Insert:** False (we don’t want this to trigger on insert) |
| 24 | + - **Update:** True (it should trigger on updates) |
| 25 | + |
| 26 | +4. **Set Conditions:** |
| 27 | + - **Condition:** |
| 28 | + ```javascript |
| 29 | + current.state == 'Resolved' && current.resolved_at <= gs.daysAgo(7) |
| 30 | + ``` |
| 31 | + - This condition checks if the incident is in the "Resolved" state and whether the resolution date is more than 7 days old. |
| 32 | + |
| 33 | +5. **Script Logic:** |
| 34 | + - Add the following script in the **Script** field: |
| 35 | + |
| 36 | +```javascript |
| 37 | +// Automatically close incidents that have been resolved for more than 7 days |
| 38 | +current.state = 'Closed'; |
| 39 | +current.update(); // Save the change |
| 40 | +gs.info('Incident ' + current.number + ' has been auto-closed after being resolved for over 7 days.'); |
| 41 | +``` |
| 42 | + |
| 43 | +6. **Testing:** |
| 44 | + - Create a few test incidents and resolve them. |
| 45 | + - Wait for more than 7 days and check if the incidents automatically change to "Closed." |
| 46 | + - Monitor the system logs for the info message indicating the incident closure. |
| 47 | + |
| 48 | +7. **Documentation:** |
| 49 | + - Document the Business Rule in the ServiceNow application documentation, including its purpose and any necessary operational notes for administrators. |
| 50 | + |
| 51 | +--- |
0 commit comments