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

How to use SN Utils?! O man a post in a community threat is not big enough for that. Using SN Utils a world would open for you. Everyone should use SN Utils!

 

Anyway, when having SN Utils active, you can simply double click the label of a field, and a popup appears where you can directly add a value, in this case a sys_id.

Else you can do this for example through background script. More work ofcourse, with SN Utils it would just be 5 seconds?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Jim Coyne
Kilo Patron

Do you really need to be populating a variable on the form?  Is it editable by the person filling in the form?

 

Why not just get the manager from within the Workflow or Flow itself?

hii jim yes need to populate the variable on form when and requested for field is editable and when we select the option change of line manger catalog which in order guide of request for service then there is option we get change of line manager for single person so when we select that one then requestor for varibale is read only and curretn line manager filed is populating with logged in users manager name even we select the requestor for is another user