02-21-2020 01:54 AM
Hello,
Does anyone know how to list users in a group? I would like to create a workflow to deploy VMs for all users in a group. I do not want to define the numer of cloned VMs as input variable, just the group name. The workflow shoud fetch all users from the group, create the VM, and assign it to the user. I searched for some sample code on te Index page, but neither one fits. Thanks in advance.
Best regards,
Krzysztof
02-22-2020 09:59 AM
I managed to handle this. In case someone has similar needs, here is the hint (just an excerpt from the script):
// common report handling functions ommited for brevity
var inputGroupId = input.InGroupId;
var groupReportName = "AccountsFeature.group.table_config";
var groupReportContext = util.createContext("global_admin", null, null);
var groupReport = getReportView(groupReportContext, groupReportName);
groupReport = groupReport.filterRowsByColumn("Group ID", inputGroupId, false);
if (groupReport.rowCount() != 1)
{
logger.addError("Group with ID [" + inputGroupId + "] not found!");
ctxt.setTaskStatusMessage("Group with ID [" + inputGroupId + "] not found!");
ctxt.setFailed("Group with ID [" + inputGroupId + "] not found!");
exit;
}
else
{
var groupName = groupReport.getColumnValue(0, "Group Name");
logger.addInfo("Group ID [" + inputGroupId + "] is [" + groupName + "]");
var userList = "";
var userReportName = "AccountsFeature.user.table_config";
var userReportContext = util.createContext("global_admin", null, null);
var userReport = getReportView(userReportContext, userReportName);
userReport = userReport.filterRowsByColumn("User Group", groupName, false);
logger.addDebug("*** Found users [" + userReport.rowCount() + "]");
for (i=0; i<userReport.rowCount(); i++)
{
var userName = userReport.getColumnValue(i, "Login Name");
logger.addDebug("*** Found user [" + userName + "]");
userList = userList + userName + ",";
}
// Remove last coma
userList = userList.substring(0, userList.length()-1);
output.OutUserList = userList;
}
Now, you can pass OutUserList to the Start Loop task for iteration.
Cheers,
Krzysztof
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide