Help with a Run Script in Workflow for AD Orchestration - Add User to Group

jlaue
Kilo Sage

Hello - 

I am working on a run script activity in a workflow that utilizes the outputs of this for an Add User to Group AD Orchestration activity. 

When I test it, I keep getting this error:

The (&(objectClass=Group)(samaccountname=)) search filter is invalid.
HRESULT: [-2147024809]

Stack Trace: at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()
at System.DirectoryServices.DirectorySearcher.FindOne()
at CallSite.Target(Closure , CallSite , Object )

 

Here is the code that I have in my Run Script activity:

//set the username-samaccountname

var un = current.variable_pool.requested_for.user_name;
workflow.scratchpad.username = un;

//set the AD group to add them to


if (current.variable_pool.requested_for.location.u_region == '725') {
var group = "Inventory Search West - BO";
}

if (current.variable_pool.requested_for.location.u_region == '810') {
var group = "Inventory Search TCI - BO";
}

if (current.variable_pool.requested_for.location.u_region == '723') {
var group = "Inventory Search Southwest - BO";
}

if (current.variable_pool.requested_for.location.u_region == '724') {
var group = "Inventory Search Southeast - BO";
}

if (current.variable_pool.requested_for.location.u_region == '722') {
var group = "Inventory Search Northeast - BO";
}

if (current.variable_pool.requested_for.location.u_region == '721') {
var group = "Inventory Search Midwest - BO";
}

if (current.variable_pool.requested_for.location == '880') {
var group = "Inventory Search Catalog - BO";
}

workflow.scratchpad.group = group;

 

 

Thanks!!

 

1 ACCEPTED SOLUTION

I was able to get this sorted.  Had to dot walk into the name field, also changed up the code a bit.  Working now.

 

var un = current.variable_pool.requested_for.user_name;
workflow.scratchpad.username = un;


var reg = current.variables.requested_for.location.u_region.name;
var loc = current.variables.requested_for.location.name;

if (reg == '721') {
workflow.scratchpad.group = "Inventory Search Midwest - BO";
}
if (reg == '725') {
workflow.scratchpad.group = "Inventory Search West - BO";
}
if (reg == '810') {
workflow.scratchpad.group = "Inventory Search TCI - BO";
}
if (reg == '723') {
workflow.scratchpad.group = "Inventory Search Southwest - BO";
}
if (reg == '724') {
workflow.scratchpad.group = "Inventory Search Southeast - BO";
}
if (reg == '722') {
workflow.scratchpad.group = "Inventory Search Northeast - BO";
}

if (loc == '880') {
workflow.scratchpad.group = "Inventory Search Catalog - BO";
}

 

 

View solution in original post

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

Are you passing ${workflow.scratchpad.group} to your powershell activity as an input?


Please mark this response as correct or helpful if it assisted you with your question.

Hello - Yes, I am passing it through as a powershell activity.  I will attach a screenshot of that.  

Just to note, I am successfully adding users to groups with a few other workflows.  This is the only one that I need to go in and check on the user's region to determine the correct group to add them to.  I think the issue might be with my 'If' statements for the Group variable, but I am not sure.

 

 

Hello - 

If I comment out all those If statements and just declare the variable with the group name, it works.  Can anyone help with the code on how I can dynamically set the variable?  Thanks!!

 

var un = current.variable_pool.requested_for.user_name;
workflow.scratchpad.username = un;

// if (current.variable_pool.requested_for.location.u_region == '725') {
// var group = "Inventory Search West - BO";
// }

// else if (current.variable_pool.requested_for.location.u_region == '810') {
// var group = "Inventory Search TCI - BO";
// }

// else if (current.variable_pool.requested_for.location.u_region == '723') {
// var group = "Inventory Search Southwest - BO";
// }

// else if (current.variable_pool.requested_for.location.u_region == '724') {
// var group = "Inventory Search Southeast - BO";
// }

// else if (current.variable_pool.requested_for.location.u_region == '722') {
// var group = "Inventory Search Northeast - BO";
// }

// else if (current.variable_pool.requested_for.location.u_region == '721') {
// var group = "Inventory Search Midwest - BO";
// }

// else if (current.variable_pool.requested_for.location == '880') {
// var group = "Inventory Search Catalog - BO";
// }

var group = "Inventory Search Catalog - BO";

workflow.scratchpad.group = group;

I was able to get this sorted.  Had to dot walk into the name field, also changed up the code a bit.  Working now.

 

var un = current.variable_pool.requested_for.user_name;
workflow.scratchpad.username = un;


var reg = current.variables.requested_for.location.u_region.name;
var loc = current.variables.requested_for.location.name;

if (reg == '721') {
workflow.scratchpad.group = "Inventory Search Midwest - BO";
}
if (reg == '725') {
workflow.scratchpad.group = "Inventory Search West - BO";
}
if (reg == '810') {
workflow.scratchpad.group = "Inventory Search TCI - BO";
}
if (reg == '723') {
workflow.scratchpad.group = "Inventory Search Southwest - BO";
}
if (reg == '724') {
workflow.scratchpad.group = "Inventory Search Southeast - BO";
}
if (reg == '722') {
workflow.scratchpad.group = "Inventory Search Northeast - BO";
}

if (loc == '880') {
workflow.scratchpad.group = "Inventory Search Catalog - BO";
}