Why am i getting unreachable code on the following code?

MIck11
Kilo Contributor

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' ;

}
}
}

7 REPLIES 7

Anitha H V
Giga Expert

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

Harshal Gawali
Giga Guru

Hi,

There is an issue in addQuery method as mentioned by @Anitha H V . what is "sys_user"? it is not defined in your code. please make correction on that line then try to run your code.

Regards,

Harshal.

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes thanks for the quick response will try that.