- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 07:37 AM
I have an intake form with a List Collector variable (Variable: list_role) on it which references a table (Table: u_role).
I have another table (Table: u_approvers1) that has a reference to the same table.
Within this item's workflow, I need to be able to take the values from list_role, compare them against the tables in the u_approvers1 Table, and create Approval records for each.
What's the best way to attack this? I have the start of what i think is needed to pull list_role apart but after that I'm not sure what to do with it.
*****
var list = current.variables.list_role.toString();
var array = list.split(",");
for (var i=0; i < array.length; i++) {
var rec = new GlideRecord('u_approvers1');
What do I do here?
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 10:17 AM
I understand that, but if you're using a Group Approval activity, that requires the returned array contain group ids. Because you're using user ids, I think you want to use a User Approval activity instead of a Group Approval activity.
See: Group Approval and User Approval
Group Approval says
User Approval says
So, if you're using sys_ids that are sys_user records, you want to use a User Approval activity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 07:43 AM
Hi Shane,
You should be able to query GlideRecord with the IN operator with current.variables.list_role.toString();
For example, if I wanted to query incidents on a comma-delimited list, I could do it like this:
// If I want to query incidents by sys_id:
// sys_ids represents a comma-delimited list of sys_ids.
var sys_ids = "85071a1347c12200e0ef563dbb9a71c1,965c9e5347c12200e0ef563dbb9a7156";
// create a new GlideRecord instance for incident
var incidents = new GlideRecord("incident");
// add the query of sys_id "IN" the comma delimited list
incidents.addQuery("sys_id", "IN", sys_ids);
incidents.query();
// Loop over them
while (incidents.next()) {
// inside of this loop, you have access to each incident record.
gs.print(incidents);
}
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 08:51 AM
I think I'm painfully close here, but not sure what I'm missing. (disregard the Table name differences from my original post, not worth the effort to change them from reality)
This is what I have in an Advanced Group Approval script:
var answer = [];
//split up the initial Role array
var list = current.variables.list_role.toString();
var listArr = list.split(',');
for (var i=0;i<listArr.length;++i) {
gs.log("Reference value is: " + listArr[i]);
//find the Approval Reference records that match
var approval = new GlideRecord('u_approval_reference');
approval.addQuery('u_red_prairie', listArr[i]);
approval.addQuery('u_active', true);
approval.query();
while (approval.next()){
gs.log("Sys ID of App Ref: " + approval.sys_id);
gs.log("App Ref Approver: " + approval.u_approver);
//for each found Approval Reference record, provide the u_approver
answer.push(approval.u_approver.toString());
}
}
All of the gs.log entries are providing the sys_ids I would expect to see, but this Activity in the Workflow keeps skipping. Do you know why the 'push' doesn't seem to be working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 09:04 AM
Have you verified there are users in the group? And the sys_ids you're pushing are sys_ids that belong to sys_user records?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 09:11 AM
Oh wait -- this is a Group Approval? That requires an array of sys_ids for groups (sys_user_group). You probably want to use a User Approval activity.