Hide and show fields on form based on roles

Renu9
Tera Contributor

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

7 REPLIES 7

HrishabhKumar
Kilo Sage

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.

 

Hi @HrishabhKumar 

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:

(function executeRule(current, previous /*null when async*/ ) {
   
    g_scratchpad.group_member = gs.getUser().isMemberOf('Investigations');
 
})(current, previous);

 

UI policy:

function onCondition() {
 if(g_scratchpad.group_member)
 {
    alert("into true");
    g_form.setDisplay('state', 'true');
    g_form.setDisplay('assigned_to', 'true');
   
 }

else{
    alert("into false");
    g_form.setDisplay('state', 'false');
    g_form.setDisplay('assigned_to', 'false');
}
}

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.

ui policy.PNG

 

Hope this helps you.