- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 08:01 AM
Hello.
I have one requirement.
User from portal end user can able access the Category GBS HR USA and GBS HR Mexico. both the category only accessible only User Department cantinas HR and Department is Human Resources.
I have write On change catalog client script
Kindly check the code user end. This code is not working. if i remove the "department === 'HR' &&" Only department == 'HUMAN RESOURCES' user can able to view the category.
Kindly help me on this code. it would be helpful for my development
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 09:22 AM - edited 06-19-2025 09:23 AM
Hello @Vurukonda Sai 1 ,
Thanks for sharing your use case. I think the issue relies in the line -" if (department === 'HR' && department == '487bb6a2dbb0d01020e3de0cd396197d')"
This will always fail, because department can't simultaneously equal both "HR" and the sys_id.
I would suggest to add the alert and check what is getting returned and accordingly update your condition.
Let me know if you need further help😀.
Please Mark my answer as Helpful👍 and Accepted✔️, if it helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 09:35 AM
As Vrushali said you have two checks on department when only one can be true. The way you are querying user details the department should return the sys_id. Thus you need to update your if statement condition to remove "department === 'HR'". This would leave your script condition as:
if(department == '487bb6a2bb0d01020e3de0cd396197d' && country == 'MX' || g_user.hasRole('admin'))
No change is necessary to the country evaluator since in glide ajax the country code is returned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 09:22 AM - edited 06-19-2025 09:23 AM
Hello @Vurukonda Sai 1 ,
Thanks for sharing your use case. I think the issue relies in the line -" if (department === 'HR' && department == '487bb6a2dbb0d01020e3de0cd396197d')"
This will always fail, because department can't simultaneously equal both "HR" and the sys_id.
I would suggest to add the alert and check what is getting returned and accordingly update your condition.
Let me know if you need further help😀.
Please Mark my answer as Helpful👍 and Accepted✔️, if it helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 09:35 AM
As Vrushali said you have two checks on department when only one can be true. The way you are querying user details the department should return the sys_id. Thus you need to update your if statement condition to remove "department === 'HR'". This would leave your script condition as:
if(department == '487bb6a2bb0d01020e3de0cd396197d' && country == 'MX' || g_user.hasRole('admin'))
No change is necessary to the country evaluator since in glide ajax the country code is returned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 09:39 AM
Hi @Vurukonda Sai 1 ,
try this
just added a alert for testing purpose just to check whether you are even receiving the response (remove it if you are successfully getting the response)
if not also share the script of script include (UserDetails) better share the screenshot of script include(what to see name API name scope etc) along with code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('UserDetails');
ga.addParam('sysparm_name', 'getInfo');
ga.addParam('sysparm_user_id', g_user.userID);
ga.getXMLAnswer(getResponse);
function getResponse(answer) {
alert(answer + typeof answer); // remove this just added for the testing purpose
answer = JSON.parse(answer);
var department = answer.department;
var country = answer.country;
if ((department == 'HR' || department == '487bb6a2dbb0d01020e3de0cd396197d') && country == 'MX' || g_user.hasRole('admin')) {
g_form.addOption('u_category', "GBS HR Mexico", "GBS HR Mexico");
g_form.addOption('u_category', "gbs_hr_usa", "GBS HR USA");
} else {
g_form.removeOption('u_category', "GBS HR Mexico");
g_form.removeOption('u_category', "gbs_hr_usa");
}
}
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 09:44 AM
var UserDetails = Class.create();