How to write Advanced reference qualifier & Script Include

Mi4
Tera Expert

Hi,

I want to set a person who belongs to the same department as the applicant's department.

But it returns an error..

What's wrong?

 

Script Include:

var getMyDepartments = Class.create();

getMyDepartments.prototype = {
initialize: function() {},

getDepartmentUsers: function() {
var usersList = "sys_idIN";
var grUser = new GlideRecord('sys_user');

grUser.addQuery('company', gs.getUser().getCompanyID());
grUser.addQuery('department', gs.getUser().getDepartmentID());
grUser.query();

while (grUser.next()) {
usersList = usersList + ',' + grUser.sys_id;
}
},
type: 'getMyDepartments'
};

 

variable Reference qualitifier:

find_real_file.png

 

System log:

find_real_file.png

Regards,

1 ACCEPTED SOLUTION

Hi,

you can create new one with some other name and keep accessible from as All application scope

var getMyDepartments2 = Class.create();

getMyDepartments2.prototype = {
 initialize: function() {},

getDepartmentUsers: function() {

var userRec = new GlideRecord('sys_user');
userRec.get(gs.getUserID());
var department = userRec.getValue('department');

 var usersList = [];
 var grUser = new GlideRecord('sys_user');

grUser.addQuery('company', gs.getUser().getCompanyID());
 grUser.addQuery('department', department);
 grUser.query();

while(grUser.next()) {
 usersList.push(grUser.getUniqueValue());
 }

return 'sys_idIN' + usersList;

 },
 type: 'getMyDepartments2'
};

call it like this from ref qualifier:

javascript: new x_223778_upload_li.getMyDepartments2().getDepartmentUsers();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

are you running this in scoped application? also both the field and script include is in same scope

can you change the script include name to this getMyDepartments1 and update code as below

you were not returning the usersList from script include

var getMyDepartments1 = Class.create();

getMyDepartments1.prototype = {
 initialize: function() {},

getDepartmentUsers: function() {
 var usersList = [];
 var grUser = new GlideRecord('sys_user');

grUser.addQuery('company', gs.getUser().getCompanyID());
 grUser.addQuery('department', gs.getUser().getDepartmentID());
 grUser.query();

while(grUser.next()) {
 usersList.push(grUser.getUniqueValue());
 }

return 'sys_idIN' + usersList;

 },
 type: 'getMyDepartments1'
};

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi.

Thank you for reply.

Yes, both are in the same scope application.

find_real_file.png

find_real_file.png

And, again returns the same error.

 

find_real_file.png

Hi,

you should remove client callable checkbox;

also use this javascript: new getMyDepartments1().getDepartmentUsers();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi,

Again error..

find_real_file.png

find_real_file.png

find_real_file.png