- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 06:54 AM
Hi Experts,
I have created Two different variable set and i want to show one at one time based on the logged in user.
Case: If logged in User Employee type = Permanent then show variable set 1. Else show variable set 2.
Please suggest me how to achieve this?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 07:18 AM
Hi,
Script include
getUserInformation: function() {
var user_sys_id = this.getParameter('sysparm_user_id');
var user = new GlideRecord('sys_user');
user.get(user_sys_id);
if (user.next()) {
var typ=user.employmenttype;
return typ;
}
},
onLoad client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getUserDetails');
ga.addParam('sysparm_name', 'getUserInformation');
ga.addParam('sysparm_user_id', g_form.getValue('caller_id'));
ga.getXML(parseUserResponse);
function parseUserResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer=='permenant'){
g_form.setVisible("VARIABLESETname1",true);
g_form.setVisible("VARIABLESETname2",false);
}
else{
g_form.setVisible("VARIABLESETname2",true);
g_form.setVisible("VARIABLESETname1",false);}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 06:58 AM
Hi
Did you tried creating UI Policy or Client script for it?
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 10:27 PM
I am using Client script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 07:00 AM
There's 2 parts to this:
1. Finding if the logged in user Employment Type = Permanent or not
2. Hiding/Showing the Variable set
For the first part, use GlideAjax and Script include in an Onload Client script.
For the second part, use the below code:
g_form.setDisplay('VARIABLE_SET_NAME',false);
see https://community.servicenow.com/community?id=community_question&sys_id=7f6834aedbfaab004abd5583ca96191d
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2022 07:18 AM
Hi,
Script include
getUserInformation: function() {
var user_sys_id = this.getParameter('sysparm_user_id');
var user = new GlideRecord('sys_user');
user.get(user_sys_id);
if (user.next()) {
var typ=user.employmenttype;
return typ;
}
},
onLoad client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getUserDetails');
ga.addParam('sysparm_name', 'getUserInformation');
ga.addParam('sysparm_user_id', g_form.getValue('caller_id'));
ga.getXML(parseUserResponse);
function parseUserResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer=='permenant'){
g_form.setVisible("VARIABLESETname1",true);
g_form.setVisible("VARIABLESETname2",false);
}
else{
g_form.setVisible("VARIABLESETname2",true);
g_form.setVisible("VARIABLESETname1",false);}
}