Set the current line manager for requestor for

Dipali11
Tera Contributor

Hi  i have service catalog and in that i need to populate the current line manager for requestor for field currently it is fetching value of logged in users manager , and the current_line_manager variable is reference field and its default value is javascript:gs.getUser().getManagerName so even if we changed the requested for it taking logged in users manager name 

Dipali11_0-1713499287192.png

tried below script include and client script 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below

   if(newValue == ''){
        g_form.clearValue('current_line_manager');
    }

    var ga = new GlideAjax('GetManagerName');
    ga.addParam('sysparm_name', "getManager");
    ga.addParam('sysparm_req', g_form.getValue('requestor_for'));
    ga.getXMLAnswer(function(answer){
        alert("hellow");
       
            g_form.setValue("current_line_manager", answer);
           
    });
}
 
 
script include:
var GetManagerName = Class.create();
GetManagerName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getManagerName: function() {



        var user = this.getParameter('sysparm_id');
        var mg = new GlideRecord("sys_user");
        mg.addQuery("sys_id", user);
        mg.query();
        if(mg.next()){
            return mg.manager.toString();
        }


    },


    type: 'GetManagerName'


});
 
kindly advise whats wring here its not working 
7 REPLIES 7

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Any reason why you are doing this scripted, and not no-code?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hey Mark ,

cause auto populate feature is not working for current_line_manager field as this variable is created under current line manager variable set hence for that auto population is not enabled 

Dipali11_0-1713500923961.png

 

So the Current Line Manager variable itself is in a Variable Set? Will that Variable always be populated based on Requested For? Which might be in the Catalog Item itself or a different Variable Set?

 

If so... still no issue using Auto Populate. It;s just that visually you can't select the Variable. Though for example using SN Utils, you can just paste in the sys_id of the Requested For variable.

 

Tested = works.

 

Or is your situation different?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

can you explian how i can use the SN utils ?