mev
Tera Contributor

Out of curiosity, aren't you only applying the first group in your array to the users AD account?  From the example above, in your "Add user to AD group" activity, you set the 'Group Name' field to: ${workflow.scratchpad.group[workflow.scratchpad.counter]}

And since you declared in your run script that workflow.scratchpad.counter = 0;   Wouldn't this only apply the first group/object in your array to the users account?

Sorry to nitpick, I'm just trying to understand your code since I also need to apply multiple groups to an AD account. I'm having some issues though.

My post is here: 

https://community.servicenow.com/community?id=community_question&sys_id=45aa0673db16db04fac7f4621f961941&anchor=answer_76cf963bdb1a5744852c7a9e0f961947

What is your "If" conditions?   in the Check Counter?

// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
// For example,
//
//   answer = ifScript();
//
//   function ifScript() {
//      if (condition is true) {
//         return 'yes';
//      }
//      return 'no';
//   }
answer = ifScript();  
  
function ifScript() {  
            var check = 'no';  
            workflow.scratchpad.counter ++;  // increment the counter  
          
            // check the counter and see if we need to go again or stop  
            if (workflow.scratchpad.counter < workflow.scratchpad.count) {  
                        check = 'yes';  
            }  
          
            return check;  
}  

drew25
Tera Contributor

This was extremely helpful.  I was able to recreate a similar workflow where we want our users to be able to subscribe to different AD distribution groups through a catalog item form.

Drew,

 

Can you please share the code for Run Script & If condition for adding multiple users to same group in the above subscription workflow?