Auto populate variable on Service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 06:08 AM
Hi All,
I wanted to know that how can we auto populate a variable in Service portal catalog form basedon the logged in user.
For.e,g: A logged in user's vertical is IT if he try to raise request under a specific catalog then one field needs to be populated in the form called "choose the support".
But if another user logged in whose vertical is BPO, and try to create request on the same catalog then this "choose the support" field should not be visible.
How can we achieve this.
Thanks in advance
Regards
Ajith A Pillai

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 07:26 AM
I dont follow what you mean by a users vertical, I assume you mean department?
Example
Field 1 - Read Only - Reference = sys_user- Default value = javascript:gs.getUserID()
You could then have a UI policy set on a Catalog Item that dotwalks from the pre populated user field to their user record and check their department name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 07:31 AM
Hi @Ajith A Pillai ,
Follow below steps.
1. create onload catalog client script on your catalog item.
2. write code to call script include.
var ga = new GlideAjax('UserUtils');
ga.addParam('sysparm_name', 'checkLogUser');
ga.addParam('sysparm_caller_sys_id', g_user.userID);
ga.getXML(ValidateVipUser);
function ValidateVipUser(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer=='true') {
g_form.setValue('field', 'Choose the support');
} else {
g_form.setDisplay('field',false);
}
}
3. create one script include with name "UserUtils" and write the below code.
var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkVipUser: function() {
var caller = this.getParameter('sysparm_caller_sys_id');
var gr = new GlideRecord('sys_user');
gr.get(caller);
if(gr.department=='IT')
return true;
else
return false
},
type: 'UserUtils'
});
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Runjay Patel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 07:32 AM
@Ajith A Pillai,
Create a Script Include to determine the logged-in user's vertical (IT or BPO).
var UserUtils = Class.create();
UserUtils.prototype = {
initialize: function() {},
getUserVertical: function() {
var userSysId = gs.getUserID();
var userRecord = new GlideRecord('sys_user');
userRecord.get(userSysId);
return userRecord.u_vertical.toString();
},
type: 'UserUtils'
};
Create a Catalog Client Script to manage the visibility and population of the choose the support field based on the user's vertical.
function onLoad() {
var userVertical = '';
var ga = new GlideAjax('UserUtils');
ga.addParam('sysparm_name', 'getUserVertical');
ga.getXMLAnswer(function(response) {
userVertical = response;
if (userVertical == 'IT') {
g_form.setVisible('choose_the_support', true);
g_form.setValue('choose_the_support', 'IT Support Team');
} else if (userVertical == 'BPO') {
g_form.setVisible('choose_the_support', false);
}
});
}
"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
Thanks & Regards,
Barath.P