looping through multiple users and group

sowmyarajaram
Tera Expert

Hi All,

I used to get the value from the catalog item and assign it to workflow scratchpad and use it in the workflow.

workflow.scratchpad.userID = current.variables.requested_for.user_name;

workflow.scratchpad.groupID = current.variables.group.u_security_group.u_sam_account_name;

This way, where "requested_for" and "group", was my reference field.

Now Im trying to have this replaced with List collector, so that I can have multiple users added to multiple groups, so for this I need to loop through users and groups. For this I tried :

var lists = current.variables.group;

  var arrays = list.split(",");

  for (var i=0; i < arrays.length; i++) {

        workflow.debug("Display value is: " + arrays[i]);

  workflow.scratchpad.groupID = arrays[i];

  }

But I get error in the workflow saying, split is not a function. Could anyone help me to resolve na d achieve this?

Any help is Appriciated!!

1 ACCEPTED SOLUTION

Here you go.. , hope this helps someone




var userdomains = [];


var answer = [];


var arr = current.variables.requested_for.toString();


var listArr = arr.split(',');


for (var i=0;i<listArr.length;++i) {


  var user = new GlideRecord('sys_user');


  user.addQuery('sys_id',listArr[i]);


  user.query();


  while(user.next()){


  answer.push(user.source.getDisplayValue());


  workflow.debug('one user' + user.source);


  var tc = new TCActiveDirectory();


  workflow.scratchpad.userDomain = tc.getDomainFromSource(user.source);


  workflow.debug("test Display value of user domain is: " + workflow.scratchpad.userDomain);


  userdomains.push(workflow.scratchpad.userDomain);



  }


}


View solution in original post

10 REPLIES 10

joshua_bice
Giga Expert

You named your variable "lists" but used "list" (missing the s) in the split method.


I tried correcting it..., no luck!!


Try this modification in your code and check


var lists = current.variables.group.toString();


Pradeep,



In the above code, Im getting "workflow.scratchpad.groupID" as the sys_id.. , How do I get the name?



Thanks,


Sowmya