Provide LIst of open records when submitting form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-22-2023 04:38 AM
I have a catalog form which is used to deactivate groups. So whenever I submit request to deactivate groups I need to update open records(incidents,request,task etc.,) assigned to group in the RITM Notes and close RITM by sending notification to requestor for like these are list of open records (count) assigned to group and request cannot be fulfilled unless these records were closed.
Can someone help me how to acheive this using scripting?
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-22-2023 04:43 AM
create BR
(function executeRule(current, previous /*, g*/) {
var groupToDeactivate = current.u_group_to_deactivate;
var gr = new GlideRecord('incident');
gr.addQuery('assignment_group', groupToDeactivate);
gr.addQuery('active', true);
gr.query();
var openRecords = [];
while (gr.next()) {
openRecords.push(gr.getDisplayValue());
}
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.parent)) {
ritm.work_notes = "Open records assigned to " + groupToDeactivate + ": " + openRecords.join(', ');
ritm.update();
sendNotification(ritm.request.requested_for, ritm, openRecords);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-22-2023 06:04 AM
Hi Harish,
I have tried to udpate in workflow but it is not showing records count which are assigned to that group.Please let me know what is the issue in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-22-2023 06:06 AM
try this
var openRecords = [];
var answer = ifScript();
function ifScript() {
var task = new GlideRecord('task');
task.addQuery('assignment_group', workflow.scratchpad.groupName);
task.addQuery('active', true);
task.query();
while (task.next()) {
openRecords.push(task.getDisplayValue());
}
if (openRecords.length > 0) {
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.parent)) {
ritm.work_notes = "Open records assigned to " + workflow.scratchpad.groupName + ": " + openRecords.join(', ');
ritm.update();
}
return 'yes';
} else {
return 'no';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2023 11:44 PM
Hi Harish,
I have tried this. but not sure why it is not updating open records in worknotes. Please let me know what is the issue here?