A field is to be editable only by certain groups and read only for the rest

Community Alums
Not applicable

Hi,

I have a scenario, on the sc_task form, a variable should be editable, if the logged in user belongs to certain group. I have written some part of the code. Kindly help.

 

Client Script

 

1.PNG

 

function onLoad() {

if (g_scratchpad.isMember == true)

   {
	g_form.
   }

}

 

Business Rule

 

2.PNG

 

3.PNG

 

(function executeRule(current, previous /*null when async*/ ) {

    if (gs.getUser().isMemberOf('TFS-ALABAMA') || gs.getUser().isMemberOf('TFS-BIRMINGHAM (RC)') || gs.getUser().isMemberOf('TFS-MID WEST'))

    {
        g_scratchpad.isMember = true;
    }

})(current, previous);

 

This is the variable to be remained editable for the following groups.

 

4.PNG

 

Regards

Suman P.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

The scratchpad variable is used in conjunction with onLoad Client Scripts when the Business Rule is triggered on display of the record, so change When to run:

BradBowman_1-1703084251807.png

Also, the value needs to be a string to get passed to the client, and it's a good idea to always set a value to prevent any errors on the client, so change your BR script:

 

(function executeRule(current, previous /*null when async*/ ) {
    if (gs.getUser().isMemberOf('TFS-ALABAMA') || gs.getUser().isMemberOf('TFS-BIRMINGHAM (RC)') || gs.getUser().isMemberOf('TFS-MID WEST')) {
        g_scratchpad.isMember = 'true';
    } else {
        g_scratchpad.isMember = 'false';
})(current, previous);

 

Then your Catalog Client Script would look like this:

 

function onLoad() {
    if (g_scratchpad.isMember == 'false') {
	    g_form.setReadOnly('variable_name', true);
    }
}

 

of course replacing variable_name with the name of your variable.

View solution in original post

6 REPLIES 6

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @Community Alums ,

 

Step 1: Create a display Business rule with script as below on sc_task table.

 

 

 

(function executeRule(current, previous /*null when async*/) {
   
 if (gs.getUser().isMemberOf('grp1 name') || gs.getUser().isMemberOf('grp2 name') )

    {
        g_scratchpad.isMember = true;
    }

})(current, previous);

 

 

Now create a Onload catalog client script to hide the variable.

 

 

function onLoad() {
   
var test = g_scratchpad.isMember;

if(test ==true){
	g_form.setReadOnly('variable_name',true);
}
}

 

 

Kindly mark my answer as Correct and helpful based on the Impact.

Regards,

Siddhesh

Hello @Community Alums ,

Haven't you seen my solution? As I given the exact same answer way before...If this help you please mark as helpful