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.

Siva Sandilya V
ServiceNow Employee
ServiceNow Employee

Below code is helpful to get manager hierarchy with right number of loops

var manager_list = [];

var user_rec = new GlideRecord("sys_user");

user_rec.addQuery("user_name","test.user");

user_rec.query();

if(user_rec.next()){

  var mngr = user_rec["manager"]; 

   while(mngr != '' && manager_list.indexOf(mngr.getValue("user_name")) == -1){

      manager_list.push(mngr.getValue("user_name"));

      mngr = mngr["manager"];   

    }

}

3 Comments