How do i add manager to a user?

Niclas Perjus
Kilo Contributor

Hi, I've just imported all our users from LDAP using the default transform map. https://docs.servicenow.com/bundle/orlando-platform-administration/page/integrate/ldap/concept/c_LDA... Everything seemed to work fine, but I can see manager on a user, or how to add it.

5 REPLIES 5

Jaspal Singh
Mega Patron
Mega Patron

Hi Niclas,

For the LDAP Server can you ensure you pass the manager attribute as well in the Attribute field that is responsible for pulling details.

find_real_file.png

Priyanka Chandr
Mega Guru

Hi,

script to the transform map:

 

Target field: manager

 

target table: User [sys_user]

 

Referenced value field name: email

 

Use source script: true

 

Script:

 

if(!source.u_manager.nil()) {

 

    var manager = new GlideRecord('sys_user');

 

    manager.addQuery('source', 'CONTAINS', source.u_manager);

 

    manager.query();

 

 

 

if(manager.next())

 

          answer=manager.sys_id;

 

    else

 

          answer='';

 

}

Refer this also :https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/script/server-scripting/reference/r_TransformationScriptVariables.html

Please mark it correct and helpful

Thanks

johnfeist
Mega Sage
Mega Sage

Hi Niclas,

You need to confirm that the manager is in your LDAP source (e.g. Active Directory).  We are doing our LDAP sync with AD and the manager is automatically included in the upload.  There is an On Complete script in the default import set that specifically goes through the data to assure that managers have been assigned wherever possible.

If you want to separately load managers you'll need to remember that Manager in sys_user is a reference into sys_user.  To accurately load the managers via import/transform, you'll need to have an import set that has at least two fields, one to uniquely identify the employee and a similar one for the manager.  The likely candidate is email address.

You may need to add a script to your transform map to do the look up of the manager based on their email and set the sys_id. Something like this:

var users = new GlideRecord("sys_user");
users.get("email", "<your import variabel name>");
target.manager = users.sys_id;

You can expand the above for conditions like the manager is not found, etc.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

TheSwede86
Giga Contributor

Hi all,

Thank you for your replies.

@Niclas Perjus is a colleague of mine so I'll also post in this thread.

@Jaspal Singh 
We have the current attributes defined:
givenname,sn,samaccountname,source,mail,l,title,department,manager

If I understand the documentation here correctly:
https://docs.servicenow.com/bundle/orlando-platform-administration/page/integrate/ldap/task/t_Specif...

I need to explicitly specify attributes (more precisely "dn" and "manager" at least) in order for the default script in "Table Transform Map" > "LDAP User Import" to work if I understand correctly?:

//
// The manager coming in from LDAP is the DN value for the manager.  
// The line of code below will locate the manager that matches the
........

So even if I leave the "attributes" field alone (which per default should import all attributes if its blank) then the script won't work and I need to explicitly state at least "dn" and "manager"?

@Priyanka Patil 
AFAIK the necessary script and prerequisites are already put in place?
I am a systems administrator and not a developer though so I might misunderstand the script put in place under "LDAP User Import" (see snippet above).

@johnfeist 
I can see in my LDAP user import that the "Manager" attribute is indeed imported as FDN.
Example for "Jane Doe" which has "John Doe" as her manager, then the "Manager" imported into SN is:
CN=John Doe,OU=Users,DC=ad,DC=mycompany,DC=com

However if I look up "Jane Doe" in SN I don't see any "Manager" field at all, not even a field containing a blank value or the full DN.

AFAIK leaving everything as default and only configuring the attributes mentioned above in my reply to Jaspal then the users should have a "Manager" field and that value should link to the user in SN which is that persons manager (the script looks up the FDN and instead of displaying the DN in text actually links to the user in question)?