Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to get name from script include instead of sys_id?

madhvi
Giga Contributor

I have to create module which shows all cases which opened_for.department is same as current users Access Department(field available on HR profile table).Scope is cases of all child department as well.

My script include is :

finaldepart: function () {
var cuser = gs.getUserID();
var finaldep = [];
var viewdep = new GlideRecord( 'sn_hr_core_profile' );
viewdep.addQuery("user", cuser);
viewdep.addQuery("u_access_dep","!=",'');
viewdep.query();
if (viewdep.next()){
return viewdep.u_access_dep;
}
else {
return null;
}
},

allDepartment: function() {

var myDept = this.finaldepart();
var deptmt = [];
var child = new GlideRecord( 'dept table' );
child.addQuery( 'u_active', true );
child.addQuery( 'u_parent', myDept);
child.query();
while (child.next()){
deptmt.push(child.sys_id.toString());
}
deptmt.push(myDept.toString());
return deptmt.join(',');
},

I am not able to convert sys_id into department names from this.Any suggestions? 

6 REPLIES 6

It didnt work.i had already tried.

MGanon
Tera Guru

These may be a separate issue but does viewdep return records?
    viewdep.addQuery("u_access_dep","!=",'');
might be better with:
    viewdep.addNotNullCondition('u_access_dep');