Provide LIst of open records when submitting form

Shahida07
Tera Contributor

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

4 REPLIES 4

Harish Bainsla
Tera Sage
Tera Sage

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);

 

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

 

// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
// For example,
//
answer = ifScript();
 
function ifScript() {
var task = new GlideRecord('task');
task.addQuery('assignment_group',workflow.scratchpad.groupName);
task.addQuery('active',true);
task.query();
var openRecords = [];
if(task.next())
{
openRecords.push(task.getDisplayValue());
return 'yes';
}
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 'no';
}

 

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';
}
}

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?