The CreatorCon Call for Content is officially open! Get started here.

Advanced reference qualifier on Variable set

chrisp1
Mega Sage

In the Service catalogue I have a variable set containing a number of reference fields. These include department_auth_only and auth_manager_auth_only, i'm trying to restrict the selection options of the authoriser list dependent on the department selected.

I know I need to use advance refernce qualifiers for this and I've tried ammending a script from another post as below, however it is not working for me.

Any advice would be gretly appreciated!

currently department references cmn_department

authoriser references sys_user with reference qualifier javascript:u_getDepartmentUsers()

I have created this Script Include

function u_getDepartmentUsers(){

  var usrsList = '';

  var dept = current.variables.department_auth_only;

  var usr = new GlideRecord('sys_user');

  usr.addQuery('department',dept);

  usr.query();

  while(usr.next()) {

  if (usrsList.length > 0) {

  //build a comma separated string of groups if there is more than one

  usrsList += (',' + usr.sys_id);

  }

  else {

  usrsList = usr.sys_id;

  }

  }

  // return a list of sus_user id's for the selected department

  return 'sys_idIN' + usrsList;

}

1 ACCEPTED SOLUTION

OK,


ran this as a background script to see exactly what it was doing


I remember the += is a bit funny at times and the original script is, but was returning an array


So, if you add the toString() in the two lines below, you will get the array as you expect


change the addQuery to use a sys_id of one of your groups




var usrsList = '';


          //var dept = current.variables.department_auth_only;


          var usr = new GlideRecord('sys_user');


          usr.addQuery('department','221f79b7c6112284005d646b76ab978c');


          usr.query();


          while(usr.next()) {


gs.print('user id is : ' + usr.sys_id);


          if (usrsList.length > 0) {


          //build a comma separated string of groups if there is more than one


          usrsList += (',' + usr.sys_id).toString();


          }


          else {


          usrsList = usr.sys_id.toString();


          }


          }


          // return a list of sus_user id's for the selected department


//           return 'sys_idIN' + usrsList;


gs.print('end user list is : '+ usrsList);



Cheers


View solution in original post

11 REPLIES 11

that's got it, thanks for your help


Kalaiarasan Pus
Giga Sage

Iust this should do the job for you if I am understanding your requirement correctly



return 'active=true^department='+dept;



Full script:



var UtilityScripts = Class.create();


UtilityScripts.prototype = {


  initialize: function() {


  },



  getDepartment:function(dept){


  return 'active=true^department='+dept;


  }


};