- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 06:58 PM
Hi Experts,
I have created a below client script to show/hide the related list ('task_sla.task') based on the g_user roles and other conditions specified below. The target table is sn_hr_core_case_relation
However, when I impersonate a user that doesn't have the required roles, the related list is still showing.
I would appreciate any help to fix it. Thanks in advance.
function onLoad() {
var hasRequiredRole = g_user.hasRole('1bd05f2e1bd2630083fe2fcdee4bcb47') || g_user.hasRole('df8dc7dedb3833005777255c8a9619ac');
var caseState = g_form.getValue('state');
var caseType = g_form.getValue('u_case_type');
var hrService = g_form.getValue('hr_service');
// Add your additional conditions here
var additionalConditionsMet = caseType == 'investigation' && hrService == 'Intake' && (caseState == '5' || caseState == '32' || caseState == '33');
if (additionalConditionsMet) {
if (hasRequiredRole) {
g_form.showRelatedList('task_sla.task');
} else {
g_form.hideRelatedList('task_sla.task');
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 07:59 PM
I have made few corrections and applied few alerts message to inspect the value you'r fetching , Below is the code:
function onLoad() {
var hasRequiredRole = g_user.hasRole('role1_name') || g_user.hasRole('role2_name');//provide the role name instead of sysid
var caseState = g_form.getValue('state');
var caseType = g_form.getValue('u_case_type');
var hrService = g_form.getValue('hr_service');
// Debug statements to check values
alert('hasRequiredRole: ' + hasRequiredRole);
alert('caseState: ' + caseState);
alert('caseType: ' + caseType);
alert('hrService: ' + hrService);
// Add your additional conditions here
var additionalConditionsMet = caseType == 'investigation' && hrService == 'Intake' && (caseState == '5' || caseState == '32' || caseState == '33');
gs.info('additionalConditionsMet: ' + additionalConditionsMet);
if (additionalConditionsMet) {
if (hasRequiredRole) {
g_form.showRelatedList('task_sla.task');
} else {
g_form.hideRelatedList('task_sla.task');
}
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2024 06:40 AM
Hi Amit,
Thanks you. It works now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 10:51 PM
what debugging have you done so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 10:51 PM
Hi @Michael Galang,
Your script looks good for function, it works in my instance. It would help if you tracked input value by log to ensure it is correct. On the other hand, the impersonated user should check 2 condition roles added. it will WORK.
Please Mark ✔️Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks & Best Regards,
Peter Tran