How to call a reference qualifier that filters to show only the users with same department?

ChuanYanF
Tera Guru

Dear experts,

 

I am trying to make a script include to call in a reference qualifier to show only the users with the same department with the user field in the sys_user_delegate form. But currently the return value is null for the sys_id. May I know what is wrong with my scripts and how should I modify it?
Reference Qualifier:

javascript: new global.FilterDepartmentUtils().getRefQualifier()

Script Include:

var FilterDepartmentUtils = Class.create();
FilterDepartmentUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

  getRefQualifier: function(recordId) {
    if (!recordId)
      return 'sys_id=NULL';

    var delegateRec = new GlideRecord('sys_user_delegate');
    if (!delegateRec.get(recordId))
      return 'sys_id=NULL';

    var user = delegateRec.getValue('user');
    if (!user)
      return 'sys_id=NULL';

    var userGr = new GlideRecord('sys_user');
    if (!userGr.get(user))
      return 'sys_id=NULL';

    var dept = userGr.getValue('department');
    if (!dept)
      return 'sys_id=NULL';

    return 'department=' + dept + '^roles=sn_risk_advanced.Boost - BU Lead';
  },

  type: 'FilterDepartmentUtils'
});
1 ACCEPTED SOLUTION

Hi @ChuanYanF 

use this ref qual directly

javascript:'department='+current.user.department+'^departmentISNOTEMPTY^roles=sn_risk_advanced.Boost - BU Lead'

 

ChaitanyaILCR_0-1749623904510.png

 

 

OR

 

update your script like this

var FilterDepartmentUtils = Class.create();
FilterDepartmentUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getRefQualifier: function(delegateRec) {
        if (!delegateRec || !delegateRec.user || !delegateRec.user.department)
            return 'sys_id=NULL';

        return 'department=' + delegateRec.user.department + '^roles=sn_risk_advanced.Boost - BU Lead';
    },

    type: 'FilterDepartmentUtils'
});

and Ref qual to

javascript:new global.FilterDepartmentUtils().getRefQualifier(current)

 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

4 REPLIES 4

Chaitanya ILCR
Mega Patron

Hi @ChuanYanF ,

getRefQualifier method accepts a parameter (recordId) since it's not passed it's returning sys_id=nul

what's recordId parameter here?

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

It should be the sys_id of my delegate's record. 

Hi @ChuanYanF 

use this ref qual directly

javascript:'department='+current.user.department+'^departmentISNOTEMPTY^roles=sn_risk_advanced.Boost - BU Lead'

 

ChaitanyaILCR_0-1749623904510.png

 

 

OR

 

update your script like this

var FilterDepartmentUtils = Class.create();
FilterDepartmentUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getRefQualifier: function(delegateRec) {
        if (!delegateRec || !delegateRec.user || !delegateRec.user.department)
            return 'sys_id=NULL';

        return 'department=' + delegateRec.user.department + '^roles=sn_risk_advanced.Boost - BU Lead';
    },

    type: 'FilterDepartmentUtils'
});

and Ref qual to

javascript:new global.FilterDepartmentUtils().getRefQualifier(current)

 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Ankur Bawiskar
Tera Patron
Tera Patron

@ChuanYanF 

reference qualifier shared by @Chaitanya ILCR should work

Try that and share the feedback.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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