RITM should mark as close once sc_tasks are closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 04:46 AM
Hi All,
I have created a catalog item and 5 sc_tasks will be created to different teams. once the sc_tasks are closed. The RITM should close automatically.
I tried the below business rules it's not working. Can someone please check and guide me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 05:19 AM
I think the 'IN' operator should be used within quotes.
(function executeRule(current, previous /*null when async*/ ) {
var requestItem = current.request_item;
// Check if the request item exists
if (!requestItem.nil()) {
var scTaskCount = new GlideAggregate('sc_task');
scTaskCount.addQuery('request_item', requestItem);
scTaskCount.addEncodedQuery('stateIN3,4,7'); // Use of 'IN' operator within quotes
scTaskCount.query();
scTaskCount.addAggregate('COUNT');
scTaskCount.next();
var completedTaskCount = parseInt(scTaskCount.getAggregate('COUNT'));
var totalTaskCount = new GlideAggregate('sc_task');
totalTaskCount.addQuery('request_item', requestItem);
totalTaskCount.query();
totalTaskCount.addAggregate('COUNT');
totalTaskCount.next();
var totalTasks = parseInt(totalTaskCount.getAggregate('COUNT'));
// Check if all SC tasks are completed
if (totalTasks == completedTaskCount) {
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(requestItem)) {
// Update RITM state to closed
ritm.state = 3; // Assuming '3' corresponds to a closed state
ritm.update();
}
}
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 05:21 AM
You can refer this link:
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 05:54 AM
Hi @Rohith9676 ,
I tried your problem in my PDI and it's working for me. Please check the below code
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
gs.log('REQUEST ITEM' + current.request_item);
var sct = new GlideRecord('sc_task');
sct.addQuery('request_item', current.request_item);
sct.query();
var totalCount = sct.getRowCount();
var sct1 = new GlideRecord('sc_task');
sct1.addQuery('state', IN, '3,4,7');
sct1.addQuery('request_item', current.request_item);
sct1.query();
var completedtotalcount = sct1.getRowCount();
if (totalCount == completedtotalcount) {
var ritm = current.request_item.getRefRecord();
ritm.state = 3;
ritm.update();
}
})(current, previous);
Result -
RITM got closed Completed when SC Task got closed completed
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak