Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Using array to add to multiple groups

Cindy Sim
Tera Expert
I am trying to use array to add user to multiple group in AD. Example: If user select 'xyz group' and 'qrs group'  to the variable 'what access is needed'. User should be added to 'xyz_group', 'qrs_group' respectively and same with any other groups selected. I am using following script but it's only giving me one group. any suggestions?
 
var abc = [current.variables.what_access.getDisplayValue.toString(',')];
var user= current.request.requested_for.name;
var action = current.variables.add_remove;
var answer = [];
workflow.scratchpad.group = getGroup(abc);
workflow.scratchpad.action = action;
function getGroup(abc) {
    var result = [];
    for (var i = 0; i < abc.length; i++) {
        if (abc[i] == 'xyz group') {
 
            result.push('xyz_group');
        }
        if (abc[i] == 'qrs group') {
 
            result.push('qrs_group');
        }
}
    }
    return result;
}
1 REPLY 1

AniketC85155510
Kilo Patron

Hello @Cindy Sim ,

Please give a try to the modified script below and see how it works for you.

var accessValues = current.variables.what_access.getDisplayValue().split(','); // Split the comma-separated string into an array
var user = current.request.requested_for.name;
var action = current.variables.add_remove;
var answer = [];

workflow.scratchpad.groups = getGroups(accessValues);
workflow.scratchpad.action = action;

function getGroups(accessValues) {
    var result = [];

    for (var i = 0; i < accessValues.length; i++) {
        var access = accessValues[i].trim(); // Trim any extra spaces

        if (access == 'xyz group') {
            result.push('xyz_group');
        } else if (access == 'qrs group') {
            result.push('qrs_group');
        }
        // Add more conditions for other groups as needed
    }

    return result;
}

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket