To achieve the controlled sequencing and progression of manually created change tasks,…
- User
To achieve the controlled sequencing and progression of manually created change tasks, while ensuring that a subsequent task only moves from “Open” to “Work in Progress” after the previous task is closed, you can implement a combination of scripting methods, including Business Rules and UI Actions.
Step 1: Auto-Populate Order Sequence Firstly, to auto-populate the task order sequence (e.g., 100, 200, 300), you can create a Before Insert Business Rule on the Change Task table (change_task).
- Business Rule: Auto-Populate Sequence
- Name: Auto Populate Order
- Table: Change Task (change_task)
- When to run the rule: Before Insert
- Filter Conditions: To be specified based on needs (e.g., only for specific types of Change Requests)
- Script:
var gr = new GlideRecord('change_task'); gr.addQuery('change_request', current.change_request); // Filter tasks belonging to the same change request gr.orderByDesc('order'); gr.setLimit(1); gr.query(); if (gr.next()) { current.order = parseInt(gr.order) + 100; // Increment by 100 from the last order } else { current.order = 100; // Start sequence if it’s the first task }
- Control Task Progression To ensure that a change task moves from “Open” to “Work in Progress” only after the preceding task is closed, consider following a two-step approach using scripting:
- UI Action: For Manual Status Change
- Create a UI Action on the Change Task table for users to manually initiate the status change.
- Name: Begin Work
- Table: Change Task (change_task)
- Action name: begin_work
- Script:
if (gs.hasRole('change_manager')) { // Check if user has appropriate role var gr = new GlideRecord('change_task'); gr.addQuery('change_request', current.change_request); gr.addQuery('order', '<', current.order); gr.addQuery('state', '!=', 'Closed'); // Assuming ‘Closed’ is the state to check, adjust based on your instance gr.query(); if (!gr.hasNext()) { current.state = 'Work in Progress'; // Adjust the field and value based on your requirements current.update(); action.setRedirectURL(current); } else { gs.addErrorMessage('Previous tasks must be completed before starting this task.'); } } else { gs.addErrorMessage('You do not have permissions to perform this action.'); } I tried the first script, which worked perfectly for achieving the desired result.
An issue I encountered while implementing the second script. After implementing it, I attempted to close the change task associated with order number 200 without first closing the task with order number 100. Surprisingly, the system did not throw an error as expected.
- Assistant