Set multiple user approvals based on List collector variable with non-user values

Abilash Kankip1
Tera Contributor

I've a spreadsheet with more than 100 folder names as one column and the other column contains approvers (different approver for every 1 or more folders ). I've built a table to store those folder names as String field and a reference field referencing user table for approvers. And in the catalog, I added a list collector variable referencing this folder table.

 

How to set Approver User activity based on the folders selected on the catalog? And should wait for all the approvals to open a task for fulfillment with only the approved folder access to fulfill.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Abilash Kankip1 

if workflow then use this script

Also ensure it waits for Everyone to approve -> select this option

AnkurBawiskar_0-1743405137627.png

 

answer = [];
var selectedFolders = current.variables.u_sc_folder_access.toString();
var gr = new GlideRecord('u_folder_access');
gr.addQuery('sys_id', 'IN', selectedFolders);
gr.query();
while (gr.next()) {
    var approverSysId = gr.getValue('u_folder_access_approver');
    answer.push(approverSysId);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

13 REPLIES 13

Shivalika
Mega Sage

Hello @Abilash Kankip1 

 

You first need to create an array from the List Collector stored values - they are basically comma separated strings. So Apply split on comma and separate the values in an array. 

 

Next, you already have the values separated in an array , then you can do "FOR EACH" and glide on your custom table with "look up record" action. This will give you exact record of that folder and also respective approver. 

 

Then, you can do Ask for approval action, where you add that approver. 

 

Please try this and let me know in case of issues. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Hi @Shivalika ,

 

Below is the script that I am using which is not right. May I know the correction?

answer = [];
var approvers = [];
var selectedFolders = [];
selectedFolders = current.variables.u_sc_folder_access.toString().split(',');

gs.log("Selected Folders: " + selectedFolders);

for (i = 0; i < selectedFolders.length; i++) {
    var gr = new GlideRecord('u_folder_access');
    gr.addQuery('u_folder_access_name', 'IN', selectedFolders);
    gr.query();

    while (gr.next()) {
        var approverSysId = gr.getValue('u_folder_access_approver');
        if (approverSysId && approvers.indexOf(approverSysId) === -1) {
            approvers.push(approverSysId);
        }
    }
}


if (approvers.length > 0) {
    answer = approvers.join(',');
}

 

Hello @Abilash Kankip1 

 

Where is it breaking, are you getting logs ? Of what you added ? 

 

var answer = [];

var approvers = [];

var selectedFolders = [];

 

if (current.variables.u_sc_folder_access) {

    selectedFolders = current.variables.u_sc_folder_access.toString().split(',');

}

 

gs.log("Selected Folders: " + selectedFolders.join(', '));

 

if (selectedFolders.length > 0) {

    var gr = new GlideRecord('u_folder_access');

    gr.addQuery('u_folder_access_name', 'IN', selectedFolders);

    gr.query();

 

    while (gr.next()) {

        var approverSysId = gr.getValue('u_folder_access_approver');

        if (approverSysId && approvers.indexOf(approverSysId) === -1) {

            approvers.push(approverSysId);

        }

    }

}

 

gs.log("Approvers Found: " + approvers.join(', '));

 

if (approvers.length > 0) {

    answer = approvers.join(',');

}

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Hello @Abilash Kankip1 

 

I just did this for user table, please follow the same pattern for your custom table and replace it with original field values. 

var ans = '62826bf03710200044e0bfc8bcbe5df1,a8f98bb0eb32010045e1a5115206fe3a,0a826bf03710200044e0bfc8bcbe5d7a,71826bf03710200044e0bfc8bcbe5d3b';

var managers = [];
ans = ans.split(',');
for(i=0;i<ans.length;i++)
{
	var gr = new GlideRecord('sys_user');
	gr.addQuery('sys_id',ans[i]);
	gr.query();
	if(gr.next())
	{
      managers.push(gr.manager);
	}
}
gs.print(managers.join(','));

Shivalika_0-1743397075120.png

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY