Why am i getting unreachable code on the following code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 10:37 PM
Getting 2 error messages, first one says type is defined but never user and the second message says unreachable code can someone help with this?
var Bringattributeuser = Class.create();
Bringattributeuser.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getDepartmentHeadUser: function() {
var userID = this.getparameter('syspara_sys_user');
var Gr_emp = new GlideRecord('x_bifac_hr2h_emp');
Gr_emp.addQuery('user_name', sys_user);
Gr_emp.query();
if (Gr_emp.next()) {
var deppid = Gr_emp.department.dept_head;
var Gr_dept = new GlideRecord('cmn_department');
Gr_dept.addQuery('sys_id', deppid);
Gr_dept.query();
if (Gr_dept.next()) {
var dhid = Gr_dept.sys_user;
return dhid ;
type:'Bringattributeuser' ;
}
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 10:43 PM
Hi Mick,
I guess in the below code line you have to use userID instead of sys_user.
Gr_emp.addQuery('user_name', sys_user);
Could you please check if you are passing the correct value here.
Thanks,
Anitha H V

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 10:57 PM
Hi,
There is an issue in addQuery method as mentioned by
Regards,
Harshal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 11:11 PM
Hi,
you are using wrong syntax
Update as this and there should be no error
I assume you want dept_head of the user
var Bringattributeuser = Class.create();
Bringattributeuser.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDepartmentHeadUser: function() {
var userID = this.getparameter('syspara_sys_user');
var Gr_emp = new GlideRecord('x_bifac_hr2h_emp');
Gr_emp.addQuery('user_name', userID);
Gr_emp.query();
if (Gr_emp.next()) {
var deppid = Gr_emp.department.dept_head;
return deppid;
}
},
type: 'Bringattributeuser'
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 11:23 PM
Yes thanks for the quick response will try that.