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

sachin_namjoshi
Kilo Patron
Kilo Patron

I developed below working add user to group activity in my instance.

 

find_real_file.png

 

 

 

You can set above parameters using below

 

workflow.scratchpad.ldap_server = gs.getProperty("glide.ldap.server.non_prod", "MID_SERVER_NAME");

 

workflow.scratchpad.user_name = buildsAMAccountName();

function buildsAMAccountName(){
	var lastName = current.variables.last_name.toString().trim();
	var firstName = current.variables.first_name.toString().trim();
	var numLen = workflow.scratchpad.user_exists_count.toString().length;
	var sAMAccountName = lastName.substring(0, maxLength - (numLen+1)) + firstName.substring(0, 1);
	if(workflow.scratchpad.user_exists_count > 1){
		sAMAccountName = sAMAccountName.substring(0, 7) + workflow.scratchpad.user_exists_count;
	}
	if(!userExists("user_name="+sAMAccountName.substring(0,8)))
		return sAMAccountName.substring(0,8);
	workflow.scratchpad.user_exists_count += 1;
	return buildsAMAccountName();
}

 

workflow.scratchpad.group_names

 

workflow.scratchpad.group_names = [];
var restrictedGroups = gs.getProperty("glide.user.automation.restricted.groups");
var queryResults = new JSON().decode(data.get(18).output);
for(i=0;i<queryResults.length;i++){
	var jsonObj = JSON.parse(new JSON().encode(queryResults[i]));
	var groupList = jsonObj.memberof.split("CN=");
	for(i=1; i<groupList.length; i++){
		if((groupList[i].indexOf("OU=ddd") == -1) && (groupList[i].indexOf("OU=Prin") == -1) && (groupList[i].indexOf("OU=Admination") == -1) && (groupList[i].indexOf("OU=DynamGroups") == -1) && (groupList[i].indexOf("OU=Act Directory Management") == -1)){
			var groupCN = groupList[i].split(",");
			if(restrictedGroups.indexOf(groupCN[0]) == -1)
				workflow.scratchpad.group_names.push(groupCN[0]);
		}
	}
}

if(workflow.scratchpad.group_names.length > 0){
	workflow.scratchpad.group_names = workflow.scratchpad.group_names.toString();
	activity.result = 'yes';
} else{
	activity.result = 'no';
}

 

 

Regards,

Sachin