Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Manager not updating Active Directory (AD)

gmccullough
Mega Guru

I have come to the conclusion that my search skills must be lacking as I searched every way I could think of and could never find the solution to my problem.   I had to go to Google and searched for hours until I came across this article: Updating Active Directory 'Manager' field | The ASP.NET Forums.   This article still did not tell me what I needed to know as far as setting up my "Update AD Object" Orchestration pack but provided me with the clue I needed to figure this out on my own.   Keyword is "distinguishedName", which is an attribute in AD.   SO I looked at what was in there and found that I was pulling this information to my sys_users table in the Source field. I didn't want to mess anything up that might be using this field, but I had a pesky little LDAP: in front of the data I needed to post back the manager.   Data looked something like this: LDAP:CN=test user,OU=TestAccounts,OU=IT,DC=xxxxxs,DC=xxxxxxs,DC=net. So here is what I did and I hope that it helps someone like me from spending so much time trying to figure this out.

I ran a script in the workflow to set the User and Manager to Scratchpad: (Set SRC to the Requested for manager's source field and then set SRB to the identified number of characters from the left to the colon and added 1 to that number. Lastly I set the workflow.scratchpad.manager variable to all the characters after the colon.

workflow.scratchpad.username = current.u_requested_for.user_name;

        var SRC = current.u_requested_for.manager.source;

        var SRB = SRC.indexOf(':') + 1;

workflow.scratchpad.manager = SRC.substr(SRB);

Next is the standard Query AD block to see if the username exists.

Then the Update AD Object looks like this:

find_real_file.png

Now all my manager changes in ServiceNow update automatically into our AD and I have some happy technicians, because I reduced their work load.

1 REPLY 1

Mike Patel
Tera Sage

I have done something similar in past. I had below

workflow.scratchpad.manager = current.u_requested_for.manager.source.toString().split("ldap:")[1];

and using powershell to do it

 

$user = "${current.u_requested_for.user_name}"
$manager = "${workflow.scratchpad.manager}"

SET-ADUSER $user –replace @{manager="$manager"}