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

Use getDisplayValue()


If I use the group as "list collector" variable I get an error saying "nill is not an function"



answer = ifScript();


  function ifScript() {


    if (current.variables.group.u_approval_type.nil()) {


            return 'yes';


        }


          return 'no';


  }


I just tried and it works. If you still get an error you can check as empty quotes in the if condition.


Pradeep, I'm doing dot walking like below, again Im not able to use "split".




var user = current.variables.requested_for.source;


var arr = user.split(",");



Gives an error saying, split is not a function.


ok, this is what im trying to achieve.



I used to get the userdomain and the group domain by below:



var tc = new TCActiveDirectory();


workflow.scratchpad.userDomain = tc.getDomainFromSource(current.variables.requested_for.source);


workflow.debug('User Domain=' + workflow.scratchpad.userDomain);


workflow.scratchpad.groupDomain = tc.getDomainFromSource(current.variables.group.u_security_group.u_distinguished_name);


workflow.debug('Group Domain=' + workflow.scratchpad.groupDomain);




Now since I cheanged the reference fiend to list collector, I tried below



var tc = new TCActiveDirectory();



var user = current.variables.requested_for.getDisplayValue().toString();


var arr = user.split(",");


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


    workflow.debug("Display value of userdomain 1 is: " + user);


      workflow.debug("Display value of userdomain 2 is: " + workflow.scratchpad.userDomain);


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


}



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


var arra = lists.split(",");


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


  workflow.debug("Display value of groupdomain1 is: " + workflow.scratchpad.groupDomain);


  workflow.debug("Display value of groupdomain2 is: " + group);


  workflow.scratchpad.groupDomain = tc.getDomainFromSource(group.u_security_group.u_distinguished_name);


}



Looking for some help.



Thanks,


Sowmya