Autopopulate logged in user's manager in catalog creation using script

User267
Tera Contributor
 
4 REPLIES 4

sabaanjum
Tera Contributor

Hi Mary,

We can achieve this via writing Script Include and calling it into Catalog client script

Script include

var LoggedInManager = Class.create();
LoggedInManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    userManager: function(){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID());
gr.query();
while(gr.next()){
    var a = gr.manager.getDisplayValue();
}
return a;
    },

    type: 'LoggedInManager'
});
 
Catalog client script
 
var ga = new GlideAjax('LoggedInManager');
   ga.addParam('sysparm_name','userManager');
   ga.getXML(callBack);
   function callBack(response){
       var answer= response.responseXML.documentElement.getAttribute('answer');
       g_form.setValue('user',answer);//user is a variable name in catalog item 
   }
 
 
Thanks
Saba Anjum

Mark Roethof
Tera Patron

Hi there,

 

Have you also considered doing this without script? Just checking since you are explicitly mentioning "script".

 

Kind regards,
Mark

Hi there,

i tried doing it via putting value in default value of variable.

 

javascript:gs.getUserID().getRecord().getValue('manager');

but it didnt worked

Please let me know if we can ahieve this in different and easiest way.

 

Thanks

Saba

Hi,

Is Manager field a reference field? If so, try below

javascript:gs.getUser().getManagerID()