Make a field read only for special groups

Frank1975
Kilo Guru

Hi scripting experts,

i would need some help / hints for a special requirement.

I have a checkbox on the Incident Form, which should be read only for 4 dedicated groups.

So far so easy, i created an ACL for that field and it is working as it should (ALMOST).

Problem i am facing is now, if the User is also member of a different group then the 4 , the field should be editable again.

As an example: The Service Desk Manager belongs to the Service Desk Group , to see what his folks are doing.

He also belongs to the Service Desk Manager group - and he should be able to edit this checkbox field.

But since he also belongs to the Service Desk Group, the field is also greyed out (read only) for him.

Any suggestions ?

thanks

Frank

1 ACCEPTED SOLUTION

one other way that might be cleaner...



create a read only true false flag.. and a read/write true false flag... initialize both to false



now thumb through the groups that the person is a member of.. and if it is a read only group   set read only to true..... if not set read/write to true.



when you have finished all groups you will have both flags set.. and can set the read only status if read only is true.. but read write is false.. if both are false the customer isn't in ANY groups and you decide if it is read only or not based on that.


View solution in original post

8 REPLIES 8

Deepak Negi
Mega Sage
Mega Sage

Hi  



Please find the below logic if this works for you.



var answer = false;


// pass the groups sys ids for which the field is to be readonly


var arr =['9da6deb70f4031000350bd5be1050eac','0e9169520f7321000350bd5be1050e19'];


var arr2   = gs.getUser().getMyGroups().toArray();




/*checks the group memebrship and returns:




true: if user belongs to any group which   is not in arr i.e field will be editable


false: if the user is the only the member of listed groups in arr i.e field will be readonly


*/


for(i=0; i<arr2.length; i++){


  for(j=0;j<arr.length;j++){


    if(arr2[i]!=arr[j]&&j==(arr.length-1))


              answer=true;


      if(arr2[i]==arr[j])


        break;


}



Thanks


Deepak





}


return answer;


randrews
Tera Guru

Frank.. without your code i can't really test it easily...



i would create a tag set to true.. and if the tag remains true i would mark the fields as read only...



now query the group member table using a while loop... on the if next test if the group is one of the four that is read only... if so you do nothing... in an else.. set the flag to false...



so on each entry it will check to see if it is a read only group and if so it does nothing.. if it is NOT one of those it flips the flag to false.... now end y our while loop for the group membership table search...



that should be it...   i am assuming that if they are not a member of ANY group.. the field is read only <unlicensed user.>


one other way that might be cleaner...



create a read only true false flag.. and a read/write true false flag... initialize both to false



now thumb through the groups that the person is a member of.. and if it is a read only group   set read only to true..... if not set read/write to true.



when you have finished all groups you will have both flags set.. and can set the read only status if read only is true.. but read write is false.. if both are false the customer isn't in ANY groups and you decide if it is read only or not based on that.


Frank1975
Kilo Guru

Hi all,


thanks for you suggestions,


I came up with 2 Arrays, first array is to get the groups,


second array to Flag, if the User is part of the 4 dedicated groups with a T and other Groups with a F.



then loop through the second array and if F is <=0 give Write/Read access,


anything else just read access.



Thanks a lot for your help!



See you at knowledge 16 !



Frank