Hide the Related List if the manager don't have users.

LaraReddy
Tera Guru

Hi All,
Can anyone please us on the below script:

We wrote one script include and client script to hide the Related list, If the user/manager don't have any direct reporters. But some reasons it's not wokring for us, can anyone please check and let us know where we went wrong.

Script include:

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

    getActiveUsers: function(managerSysID) {
     var usr = new GlideRecord('sys_user');
        usr.addQuery('sys_id', current.manager);
       usr.query();
var userCount = 0;
        while (usr.next()) {
           userCount++;
            }
return userCount++;
},
type: 'getManagerDirectReports'
});


Client script:

function onLoad() {
 var usrs = new GlideAjax('getManagerDirectReports');
 usrs.addParam('sysparm_name','getActiveUsers');
usrs.getXML(callbackfunction);

 function callbackfunction(response)
 {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    alert(answer);  // Example: If one user have two reporting users but in alert we're getting zero

    if(answer == 0)
    {
        g_form.hideRelatedList('direct_reports');
    }
    else{
        g_form.showRelatedList('direct_reports');

    }
 }
}


Advance thanks.


1 ACCEPTED SOLUTION

Sorry my bad,

Please update script include like this:

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

    getActiveUsers: function(managerSysID) {
var manId = this.getParameter('manager_id');
     var usr = new GlideRecord('sys_user');
        usr.addQuery('manager', manId);  // updated query
       usr.query();
return usr.getRowCount();
},
type: 'getManagerDirectReports'
});
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

11 REPLIES 11

Sorry my bad,

Please update script include like this:

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

    getActiveUsers: function(managerSysID) {
var manId = this.getParameter('manager_id');
     var usr = new GlideRecord('sys_user');
        usr.addQuery('manager', manId);  // updated query
       usr.query();
return usr.getRowCount();
},
type: 'getManagerDirectReports'
});
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thanks Anil working fine now.