Here is the example script include that can help you to get the Top Parent department name from the user department.
var DepartmentUtil = Class.create(); DepartmentUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, { getmemberDep : function (){ var gr = new GlideRecord('sys_user'); if(gr.get(this.getParameter('sysparm_user'))){ var topDep = this.getTopParent(gr.department.sys_id); return topDep; } }, getTopParent: function (dep){ var cdep=this.getParentDepart(dep); while(cdep.parent != ''){ cdep=this.getParentDepart(cdep.parent.sys_id); }return cdep.name; /*if(cdep.parent != '') cdep=this.getParentDepart(cdep); else return cdep.name;*/ }, getParentDepart: function (currentDep){ var gr = new GlideRecord('cmn_department'); if(gr.get(currentDep)){ return gr; } }, type: 'DepartmentUtil' });
No responses yet