- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2014 11:34 AM
How can I apply a reference qualifier to a department reference list. I want to control what the current user can see by a specific value in another field on the department table. I'm using Calgary so can't benefit from Eureka improvements for creating ref qualifiers.
For e.g. of what I'm trying to achieve.
All departments have a field called 'SSGROUP' (u_ssgroup on the cmn_department table). If we add the value 'ITDept' to this field, the user filling out a 'New Starter' form, should only see departments that have the 'ITDept' value in place. Query like u_ssgroupSTARTSWITHITDEPT
Access to the relevant departments is done by groups. e.g. the ITFILTER group on the sys_user_group table.
Can this be done as an Client Script on its own, or a client script calling a script include? I really could do with some help developing the scripts.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2014 07:46 AM
actually you dont need a onload script to pull the reference qualifier and put it to a field .... use the reference qualifier script in reference qual field as below
Reference qual for u_ssgrp : javascript: new userUtilsAjax().getUserDepartment()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2014 07:28 PM
You would need to write a client script, query the table and fill the value... or a display business rule too if possible
These should help
http://wiki.servicenow.com/index.php?title=Using_GlideRecord_to_Query_Tables
http://wiki.servicenow.com/index.php?title=GlideAjax
http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2014 09:01 AM
Hi Kalaiarasan
I've had a go at putting these scripts together, but with not much joy. I'm able to get data from the sys_user table and put into the u_primary_department field ok, but when i change the table to the one i really need data from, i get no data back.
Firstly from the personalized dictionary, a field called Reference Qual, i want to get the current value for loggedon person, (e.g. nameSTARTSWITHmydeptxxx) from under the cmn_department table for a field called SSGROUP. We hope to pump different queries in to this string for different departments for filtering out departments not relevant for the logged in user.
I then want to push this value into the field called Reference Qual on the new form table u_create_profile when form is loaded. So that the user only sees relevant departments to choose from on the u_primary_department drop-down field. My effort are below. Anyone know where it's going wrong? Would a business rule be better in this case?
\\ Client onLoad Script
function onLoad() {
getUserInfo();
function getUserInfo() {
var ga = new GlideAjax('userUtilsAjax'); // get the script include you make below
ga.addParam('sysparm_name', 'getUserDepartment'); // call the function inside the script include
ga.addParam('sysparm_user', g_user.userID); //when call pass the logged in user's sys_id
ga.getXML(showDepartment); // run function to set the value of the desired field
function showDepartment(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_primary_department', answer);
}
}
}
\\ Script Include
\\ Name: userUtilsAjax (this can be any name. when you create the script include it will automatically set the name in the below script)
\\ Client Callable: checked (this field must be checked in order for a client script to call it)
var userUtilsAjax = Class.create();
userUtilsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDepartment: function() {
var callerID = this.getParameter('sysparm_user');
gs.log(callerID, 'test');
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id', callerID);
grUser.query();
if(grUser.next()){
return grUser.department.getDisplayValue();
}
},
type : "userUtilsAjax"
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2014 12:18 AM
Not sure whether you want to restrict the values on the reference icon pop up or you want to auto populate the value..
Before writing this, I am assuming that you want to restrict the values on the reference icon pop up and u_primary_department and SSGROUP are both reference field and you want a reference qualifier for u_primary_department...
Reference qual for u_primary_department : javascript: new userUtilsAjax().getUserDepartment()
Script include:
var userUtilsAjax = Class.create();
userUtilsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDepartment: function() {
var currentUser = gs.getUserID();
var refQual = '';
var grUser = new GlideRecord('sys_user');
if(grUser.get(currentUser)){
refQual= 'sys_id='+grUser.department.SSGROUP.toString();
}
return refQual;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2014 07:43 AM
My apologies I didn't include the correct script in last post. WHat you sent was helpful all the same.
Yes i want to restrict the choices\values on a reference drop-down field called SSGRP.
The SSGROUP field is a String type
The SSGRP field is a Reference type
The bits in bold are the scripty bits i'm not sure of.
On the department table (cmn_department) I've typed in the query string e.g. 'GOTOnameSTARTSWITHxxxxxxxxx' into the SSGROUP field for the department the user belongs too.
Script include needs to get this query string and return the answer to the client script. The client script needs to put the answer (e.g. GOTOnameSTARTSWITHxxxxxxxxx) into the Reference Qual field for the SSGRP field on the u_create_profile table
At the moment I'm not grabbing the query string successfully and i'm not sure im putting the answer into the 'reference_qual' field correctly.
\\Client Script
function onLoad() {
getUserInfo();
function getUserInfo() {
var ga = new GlideAjax('deptFilterAjax');
ga.addParam('sysparm_name', 'getFilterDepartment');
ga.addParam('sysparm_user', g_user.userID);
ga.getXML(showFilteredDepartments);
function showFilteredDepartments(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_create_profile.u_ssgrp.reference_qual', answer);
}
}
}
\\ Script Include
var deptFilterAjax = Class.create();
deptFilterAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDepartment: function() {
var currentUser = gs.getUserID();
var refQual = '';
var grDept = new GlideRecord('cmn_department');
if(grUser.get(currentUser)){
refQual= 'sys_id='+grDept.SSGROUP.toString();
}
return refQual;
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2014 07:46 AM
actually you dont need a onload script to pull the reference qualifier and put it to a field .... use the reference qualifier script in reference qual field as below
Reference qual for u_ssgrp : javascript: new userUtilsAjax().getUserDepartment()