Hide and show fields on form based on roles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2024 11:06 PM
Hi All,
im having a requirement where on the form im having state and assigned to fields
these 2 fields should not be visible to the contact but it has to be visible for fulfillers (assignment group)
please help me how i can achieve it
Both in portal and platform it should behave the same
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 12:30 AM
Hi @Renu9
You can do that using g_scratchpad approach. I'm providing the code below, feel free to modify the code according to your requirement like.. table name, field name etc.
1) Write a Display BR on the table.
here we are setting a isMember property in g_scratchpad.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
g_scratchpad.isMember = gs.getUser().isMemberOf(current.assignment_group);
})(current, previous);
2) Write a onLoad client Script on the table.
Here we will use the isMember property and based on it we will hide the fields.
function onLoad() {
//Type appropriate comment here, and begin script below
if (!g_scratchpad.isMember) {
//Add the fields you want to hide
g_form.setDisplay('description', false);
}
}
This can help you accomplish your requirement of hiding fields on the basis of the current user being a member of the assignment group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 01:38 AM
There is already an existing on load client script using for some other purpose.
So, I created a UI policy but when I checked in portal, it is throwing browser console error. Can you please guide here
BR:
UI policy:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 02:23 AM - edited 06-03-2024 02:30 AM
Hi @Renu9 ,
I have few questions:
1) Is the BR a Display BR.
2) what is the condition of your UI Policy?
3) where are you writing the script?
4) what do you mean by "checked on portal"?
for your help Check and alter these changes:
1) Check if the BR is Display BR, and there is no additional conditions.
2) Remove all the conditions from your UI Policy, so that it runs every time, and add your code in the "Execute if true" block.
3) Make sure "Run scripts in UI type" is set to all.
Hope this helps you.