Auto populate manager name when the user is selected in Catalog portal form and ability to change that manager's name from drop down list as well

Em10
Tera Contributor

Hi there,

I have a simple catalog form where you can select the user and user's manager name should auto populate. Sometimes, manager is away for some reason, the requester should able to choose another manager from manager's drop down box. 

I've seen script include and client script but it is not working. 

 

My form will have

Requester - Reference field to sys_user table

Manager name - auto populate and ability to change from drop down box

Could you please advise? For manager dropdown box, should i create Reference field on sys_user table as well?

Can this be achievable? Thank you. 

Script include: client callable

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

    getManager:function() {

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

    } ,

    type: 'getUserLineManager'
});

Catalog Client Script

 

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

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

    var ga = new GlideAjax('getUserLineManager');
    ga.addParam('sysparm_name', "getManager");
    ga.addParam('sysparm_req', g_form.getValue('requested_for'));
    ga.getXMLAnswer(function(answer){
        
            g_form.setValue("approving_manager", answer);
        
    });
    //Type appropriate comment here, and begin script below

}

 

 

1 ACCEPTED SOLUTION

suvro
Mega Sage
Mega Sage

Zero code approach

https://community.servicenow.com/community?id=community_article&sys_id=3f0cf115db7fc190847d5ac2ca961931

View solution in original post

2 REPLIES 2

suvro
Mega Sage
Mega Sage

Zero code approach

https://community.servicenow.com/community?id=community_article&sys_id=3f0cf115db7fc190847d5ac2ca961931

Pavankumar_1
Mega Patron

Hi,

Yes it will not go to If loop in script include. Type error q is small not big one Q.

mgr.Query();  //it should be mgr.query();

 

Hope you it helps you.

Please Mark Correct/helpful if applicable, Thanks!! 

 

Regards

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar