The CreatorCon Call for Content is officially open! Get started here.

LDAPUtils setmanager processmanager based on other value than DN

marcelschneide1
Giga Contributor

Hi guys

On of my client is using the manager_employeenumber as manager value, not the DN.

As LDAPUtils setManager and processManager is using DN to map the correct manager I need to change that behavior. As LDAPUtils seem to be stored in the source code of ServiceNow which is obviously not public I cannot figure out how processManager is exactly working.

Is there anyone who encountered the same question or has a proper self written function to map manager based on another attribute than the DN?

From LDAPUtils script:

      setManager: function(source, target) {

            var ge = source.getElement(this.manager);

            if (!ge || ge.isNil())

                  return;

            this._getLdapUserUpdate();

            var ldap = new GlideLDAPUserUpdate();

            var mid =   this.ldapUserUpdate.getManagerValue(target, ge.toString());

            if (mid == null)

                  return;

            target.manager = mid;

      },

Tricky part is the getManagerValue function - somehow this function needs to know that it should look for the DN, but I need to change to lookup the employee number.

We are on Helsinki.

Thanks a lot!

1 ACCEPTED SOLUTION

marcelschneide1
Giga Contributor

For anyone requiring the scripts:



onStart


var mgr = [];



onAfter


(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {



  // 1.) first use manager attribute, if no manager found, try within onComplete (and if still not, fallback to dept head)


  // 2.) if no manager attribute set, use department head


  var ge = source.u_manager_employeenumber;



  if (!ge || JSUtil.nil(ge)) {


  target.manager = target.department.dept_head.sys_id;


  target.update();


  }


  else {


  var gr = new GlideRecord('sys_user');


  gr.addQuery('employee_number',ge);


  gr.query();


  if(gr.next()){


  target.manager = gr.sys_id;


  target.update();


  }


  else {


  // save to array used in onComplete script


  mgr.push({user: target.sys_id, mgr: ge.toString()});


  }


  }



})(source, map, log, target);



onComplete



var ldapHelper = new ldapProcessManagers();


  ldapHelper.processManagers(mgr);



Script include


var ldapProcessManagers = Class.create();


ldapProcessManagers.prototype = {


  initialize: function() {


  },



  processManagers: function(mgr) {



  var usrid = null;


  var mgrempid = null;


  var mgrSysId = null;



  for(i = 0; i < mgr.length; i++) {



  // usrid will hold sys_id of user without manager


  usrid = mgr[i].user;


  mgrempid = mgr[i].mgr;


  // get sys id of managers user record



  var gr = new GlideRecord('sys_user');


  gr.addQuery('employee_number',mgrempid);


  gr.query();


  if(gr.next()){


  mgrSysId = gr.sys_id;


  } else {


  mgrSysId = null;


  }



  var gt = new GlideRecord('sys_user');


  gt.get(usrid);


  gt.manager = mgrSysId;


  gt.update();



  }


  },



  type: 'ldapProcessManagers'


};


View solution in original post

4 REPLIES 4

marcelschneide1
Giga Contributor

Ok, solved that by re-writing the function on my own as onAfter script of the transform map.


marcelschneide1
Giga Contributor

For anyone requiring the scripts:



onStart


var mgr = [];



onAfter


(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {



  // 1.) first use manager attribute, if no manager found, try within onComplete (and if still not, fallback to dept head)


  // 2.) if no manager attribute set, use department head


  var ge = source.u_manager_employeenumber;



  if (!ge || JSUtil.nil(ge)) {


  target.manager = target.department.dept_head.sys_id;


  target.update();


  }


  else {


  var gr = new GlideRecord('sys_user');


  gr.addQuery('employee_number',ge);


  gr.query();


  if(gr.next()){


  target.manager = gr.sys_id;


  target.update();


  }


  else {


  // save to array used in onComplete script


  mgr.push({user: target.sys_id, mgr: ge.toString()});


  }


  }



})(source, map, log, target);



onComplete



var ldapHelper = new ldapProcessManagers();


  ldapHelper.processManagers(mgr);



Script include


var ldapProcessManagers = Class.create();


ldapProcessManagers.prototype = {


  initialize: function() {


  },



  processManagers: function(mgr) {



  var usrid = null;


  var mgrempid = null;


  var mgrSysId = null;



  for(i = 0; i < mgr.length; i++) {



  // usrid will hold sys_id of user without manager


  usrid = mgr[i].user;


  mgrempid = mgr[i].mgr;


  // get sys id of managers user record



  var gr = new GlideRecord('sys_user');


  gr.addQuery('employee_number',mgrempid);


  gr.query();


  if(gr.next()){


  mgrSysId = gr.sys_id;


  } else {


  mgrSysId = null;


  }



  var gt = new GlideRecord('sys_user');


  gt.get(usrid);


  gt.manager = mgrSysId;


  gt.update();



  }


  },



  type: 'ldapProcessManagers'


};


Hi Marcel,



I have similar requirement to load manager data. I am not using LDAP. we are getting the users data from a Database table   . we have created the datasource and created the transform map to load to sys_user table. Now we need to implement the same functionality as it has been handled in LDAP for loading Managers data. Kindly suggest how do i proceed?


Hi Marcel,

I have similar requirement to use manager's employee ID instead of DN value.

Can I just use the onAfter script or do I need to use onStart, onComplete and Script Include as well ?

Could you please help me with the steps on how to achieve the desired result of mapping the user's manager based on employee ID ?

Thank you.

Kind regards
Suresh