Change request should be Auto closed when Changed task is closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 11:02 PM
why my code not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2024 06:02 AM - edited 07-20-2024 06:03 AM
Hi @viswak
please refer the updated code:
(function executeRule(current, previous /*null when async*/) {
// Query for open change tasks related to the current change request
var taskGR = new GlideRecord('change_task');
taskGR.addQuery('change_request', current.sys_id);
taskGR.addQuery('state', '!=', '3'); // Assuming '3' is the closed state for tasks
taskGR.query();
// If no open tasks exist, close the change request
if (!taskGR.hasNext()) {
current.state = 3; // Assuming '3' is the closed state for the change request
current.update();
}
})(current, previous);
……………………………………………………………………………………………………
Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2024 07:51 AM - edited 07-20-2024 12:30 PM
Hi @viswak
The subject here has "Change request should be Auto closed when Changed task is closed", for that change your BR definition to run on the change_task table, and for Update. Add conditions:
'state', changes to', 'Closed' AND 'Change Request', 'Is not empty' on the "When to run" section. Use script logic:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var chgRec = new GlideRecord('change_request');
chgRec.addQuery('sys_id', current.change_request.toString());
chgRec.query();
gs.info('Auto-close change: Found ' + chgRec.getRowCount() + " Chg records");
if (chgRec.next()) {
chgRec.state = 3; // Closed choice value
gs.info('Auto-close change: Closing ' + chgRec.number);
// set madatory fields when chg is closed
chgRec.close_notes = current.close_notes;
chgRec.close_code = current.close_code;
chgRec.update();
}
})(current, previous);
Testing the above didn't work, as the OOB logic found other related change_task records that were not closed. So logic needs to be added to check that. The above may work if change_task begin close is the only one change_task record related the the change_request record, but there is other OOB behavior that is affecting closing the change request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 11:35 PM
not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 11:41 PM