- 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-26-2024 07:17 PM
Hi @Michael Galang !
Try to add all the conditions in a single if condition and then try to show / hide realted list.
Test by adding logs, > console.log('passed')
Add one condition at a time and see which condition is not evaluating to true.
Example:
If(g_user.hasRole('1bd05f2e1bd2630083fe2fcdee4bcb47') || g_user.hasRole('df8dc7dedb3833005777255c8a9619ac') || g_form.getValue('state') == '5' || g_form.getValue('u_case_type') == 'investigation' || <add more> ) {
g_form.showRelatedList('task_sla.task');
} else {
g_form.hideRelatedList('task_sla.task');
}
}
}
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right 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:31 AM
Hi Maddysunil,
Thanks you. It works now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 08:49 PM
HI @Michael Galang ,
I trust you are doing great.
To control the show/hide behavior of the related list ('task_sla.task') based on user roles and other conditions, we can make the following adjustments to your client script:
function onLoad() {
var hasRequiredRole = g_user.hasRole('role1_name') || g_user.hasRole('role2_name'); // Replace 'role1_name' and 'role2_name' with actual role names
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 (optional)
console.log('hasRequiredRole: ' + hasRequiredRole);
console.log('caseState: ' + caseState);
console.log('caseType: ' + caseType);
console.log('hrService: ' + hrService);
// Add your additional conditions here
var additionalConditionsMet = caseType == 'investigation' && hrService == 'Intake' && (caseState == '5' || caseState == '32' || caseState == '33');
console.log('additionalConditionsMet: ' + additionalConditionsMet);
// Check if all conditions are met to show/hide the related list
if (hasRequiredRole && additionalConditionsMet) {
g_form.showRelatedList('task_sla.task');
} else {
g_form.hideRelatedList('task_sla.task');
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi