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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

.toString() will not help you here. Have you tried .getDisplayValue()?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

I have tried getDisplayValue() already- it says function not recognized.

Hmmm oke.

Is it actually about this part: deptmt.push(child.sys_id.toString());

Or this part: deptmt.push(myDept.toString());

For the first, child.getDisplayValue(); should work fine.

For the second, have a look at the finaldepart function. That's returning return viewdep.u_access_dep;. Is u_access_dep a sys_id? Then indeed, this will not work. You would need to change this return.
Obviously I don't know if you use this anywhere else in your environment, so don't know if you just can change this return.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Raju Lakkam
Mega Contributor

Hi,

Try this myDept.getDisplayValue();