How can you get manager name based on logged-in user?

Raji9
Tera Expert

In the scoped application,  I am not able to use 'javascript:gs.getUser().getManagerID()' for to set   default value of the current manager.  it is not supported in the scoped application.  Is there any easiest way  to set the default value?

 

Thanks

8 REPLIES 8

@Raji 

Hope you are doing good.

Did my reply answer your question?

If so, please mark my response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

This worked for me. I was trying to populate manager Name & manager level of the logged in user. This script helped me.

Worked well for me, even for a Record Producer on a Reference Variable.

Thanks! 🙂

Hi Ankur,

Quick question - where do you add this script? I'm creating a basic catalog item where I am looking for:

  1. Requester Name
  2. Department
  3. Location
  4. Manager

I got the first 3 working - but can't figure out how to get the manager.

Catalog Client Script.

function onLoad() {
   //Type appropriate comment here, and begin script below
   
}
    var id = g_form.getValue('requested_for');
    var ga = new GlideAjax('PopUserDetails');
    ga.addParam('sysparm_name', 'findValues');
    ga.addParam('sysparm_user_name', id);
    ga.getXML(function ServerResponseParse(response) {
        var result = response.responseXML.getElementsByTagName("result");
        var department = result[0].getAttribute("department");
        var user_id = result[0].getAttribute("user_id");
        var location = result[0].getAttribute("location");
        g_form.setValue('department', department);
        g_form.setValue('user_id', user_id);
        g_form.setValue('site', location);

    });

 

Script Include:

var PopUserDetails = Class.create();
PopUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    findValues: function() {

        var result = this.newItem("result");
        result.setAttribute("message", "Returning user details");
        var userInfo = this.getParameter('sysparm_user_name');
        var userDetails = {};
        var gr = new GlideRecord('sys_user');

        gr.addQuery('sys_id', userInfo);

        gr.query();

        if (gr.next()) {


            result.setAttribute("department", gr.department.getDisplayValue());
            result.setAttribute("location", gr.location.getDisplayValue());
            result.setAttribute("user_id", gr.user_name);
			result.setAttribute("title", gr.title);

        }

        return result;

    },
    type: 'PopUserDetails'
});

 

Not sure how to get the manager added in!

any help would be amazing.

Thanks

Clinton