Hide a variable on record producer based on role of logged in user
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 05:41 AM
Hi I have a field on record producer which is in customer service scope.
that field should only visible to user with role ' sn_customerservice.customer_admin'.
How do I achieve this?
Labels:
- Labels:
-
Incident Management
7 REPLIES 7
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 06:04 AM
does this work in scoped application?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 06:13 AM
yes UI policies can be created in scoped application.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 08:57 PM
Can you try:
- replace set field name here with your field (technical) name
- If the field is not and should not be mandatory remove the setMandatory lines below
function onLoad() {
g_form.setMandatory("set field name here", false);
g_form.setVisible("set field name here", false);
if (g_user.hasRole('sn_customerservice.customer_admin')) {
g_form.setMandatory("set field name here", true);
g_form.setVisible("set field name here", true);
}
}
It will set the field visible if the user has the role 'sn_customerservice.customer_admin' or if the user is an admin.
Things to check:
- Are there any other client scripts that set this field to show or not?
- Are there any UI Policies that set this field to show or not?
- You can temporarily include an alert on the condition and check the result like so:
function onLoad() {
alert(g_user.hasRole('sn_customerservice.customer_admin'));
g_form.setMandatory("set field name here", false);
g_form.setVisible("set field name here", false);
if (g_user.hasRole('sn_customerservice.customer_admin')) {
g_form.setMandatory("set field name here", true);
g_form.setVisible("set field name here", true);
}
}