- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 06:01 AM
Hi Team,
I have problem with catalogue client script.
Requirement is Loged in user department contains HR user can able to access the HR related catagory.
I'm unable get catagory. Could please help me on this.
script here:
Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 06:06 AM
@Vurukonda Sai 1 verify below fix scripts:
Client Script:
function onLoad() {
var ga = new GlideAjax('UserDetails');
ga.addParam('sysparm_name', 'getInfo');
ga.addParam('sysparm_user_id', g_user.userID);
ga.getXML(getResponse);
function getResponse(response) {
var answer = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
var department = answer.department;
// Corrected department check
if (department === 'HR' || g_user.hasRole('admin')) {
g_form.addOption('u_category', "OneStream HR", "OneStream HR");
} else {
g_form.removeOption('u_category', "OneStream HR");
}
}
}
Script Include:
var UserDetails = Class.create();
UserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function() {
var obj = {};
var id = this.getParameter('sysparm_user_id');
var gr = new GlideRecord('sys_user');
if (gr.get(id)) {
obj.department = gr.department.toString();
// Other fields...
}
return JSON.stringify(obj);
},
type: 'UserDetails'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 06:15 AM
so what debugging did you do?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 06:06 AM
@Vurukonda Sai 1 verify below fix scripts:
Client Script:
function onLoad() {
var ga = new GlideAjax('UserDetails');
ga.addParam('sysparm_name', 'getInfo');
ga.addParam('sysparm_user_id', g_user.userID);
ga.getXML(getResponse);
function getResponse(response) {
var answer = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
var department = answer.department;
// Corrected department check
if (department === 'HR' || g_user.hasRole('admin')) {
g_form.addOption('u_category', "OneStream HR", "OneStream HR");
} else {
g_form.removeOption('u_category', "OneStream HR");
}
}
}
Script Include:
var UserDetails = Class.create();
UserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function() {
var obj = {};
var id = this.getParameter('sysparm_user_id');
var gr = new GlideRecord('sys_user');
if (gr.get(id)) {
obj.department = gr.department.toString();
// Other fields...
}
return JSON.stringify(obj);
},
type: 'UserDetails'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 06:15 AM
so what debugging did you do?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 06:24 AM
Hello @Vurukonda Sai 1 ,
Update your client script with the below code to show HR Category based on the department -
function onLoad() {
var ga = new GlideAjax('UserDetails');
ga.addParam('sysparm_name', 'getInfo');
ga.addParam('sysparm_user_id', g_user.userID);
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
// Corrected department check
if (answer == 'true') {
alert("Line 14");
g_form.addOption('request_type', "HR", "HR");
} else {
g_form.removeOption('request_type', "HR");
}
}
}
Update your script Include as well with the below code as well. Make sure your script include a client callable.
var UserDetails = Class.create();
UserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function() {
var obj = '';
var dept = '';
var id = this.getParameter('sysparm_user_id');
var gr = new GlideRecord('sys_user');
if (gr.get(id)) {
dept = gr.department.getDisplayValue();
gs.addInfoMessage("Department is - "+dept);
}
if (dept == "HR" || gs.getUser().hasRole('admin')) {
gs.addInfoMessage("Inside line 14");
return 'true';
} else {
return 'false';
}
},
type: 'UserDetails'
});
The above script worked for me on my PDI.
Thank you.