Need help setting workflow scratchpad variables

Ken Berger
Giga Guru

Hi all,

I am trying to set the scratchpad variables that will go to a PS script workflow activity that assigns a user to multiple groups.  As far as I can see, the script should set the scratchpad with the following:

GroupNames (an array containing the AD group names)

UserName (the user to be added to the groups)

When I test the inputs on the workflow activity I am not getting any error and my test user is being added to the AD groups properly.  But when I run the workflow the AddUserToAdGroups activity is failing.  A bit of testing reveals that the scratchpad values are not being passed to the activity and/or the PS script.

As far as I can tell, I am setting the activity up properly but I am fairly new to ServiceNow and may be missing something.  Any advice as to what could be keeping the scratchpad values from reaching the script is appreciated.

Thanks in advance!

Here is how I have my input on the activity set:

I also tried as below:

Here is my scratchpad script:

var adobeApps = which_product_are_you_requesting+'';
var apps = adobeApps.split(',');
var adobeSAMs=[];

for (var i=0; i<apps.length; i++) {
	var grGroup = new GlideRecord('sys_user_group');
	if (grGroup.get(apps[i])) {
		adobeSAMs.push(grGroup.u_samaccountname);
	}
}

workflow.scratchpad.GroupNames = adobeSAMs.join(',');

var gr = new GlideRecord('sys_user');
if (gr.get(current.variable_pool.who_are_you_requesting_this_software_for)) {
	workflow.scratchpad.UserName = gr.u_samaccountname;
}

workflow.info('at ' + activity.name + ' the scratchpad is '+ new JSON().encode(workflow.scratchpad));

Here is my scratchpad output:

 And my .ps1 script":

import-module "$executingScriptDirectory\AD\ActiveDirectory"

if (test-path env:\SNC_groupnames) {
    $groupnames = $env:SNC_groupnames;
    $username = $env:SNC_username;
};

$groupsArray = $groupnames -split ',';
foreach ($groupname in $groupsArray) {
    Add-ADGroupMember -Server $computer -Identity $groupname -Members  $username 
}
0 REPLIES 0