Set secured field in javascript according to general attribute

135 Views Asked by At

My mission is: if the owner of the record is loading the form nothing changes but if not the record's owner loading the form so a X field must be a 'secured field' (can see the field not the value on form and not on advanced search) - is it possible ? I'm not sure that it is possible because on advanced search it will not look at the record's owner data.

A solution that I thought about is when the form is loading I will check if the user is the owner and if so I will give him a security role or add him to a team that has the privilege to my secured field, is it sounds logical?
Is there an other option to solve that case ?

2

There are 2 best solutions below

0
Arun Vinoth-Precog Tech - MVP On

This is a tricky requirement, because we need Field level security enabled for that attribute and based on some field value in a record (owner) - the user will get access to the secured field. But usually FLS will give permission for set of users/team configured in FLS profile. We cannot create a team for each record, Access team cannot be used for this, Security role is not helpful in this scenario.

Similar topic discussed on community forum and this blog post talks about using sdk call to utilize “Share secured fields” functionality.

You can use similar snippet in plugin/workflow/Javascript for sharing it with owner on create/update. This will work in form, advanced find and everywhere.

Entity poaa = new Entity("principalobjectattributeaccess");
 poaa["attributeid"] = attributeResponse.AttributeMetadata.MetadataId;
 poaa["objectid"] = new EntityReference(entityName, objectId);
 poaa["readaccess"] = allowRead;
 poaa["updateaccess"] = allowUpdate;
 if (shareWithTeam)
 {
 poaa["principalid"] = new EntityReference("team", principalId);
 }
 else
 {
 poaa["principalid"] = new EntityReference("systemuser", principalId);
 }
 
service.Create(poaa);
0
Khadim Ali On

I think this should work. Give it a try please.

  • Set up a Retrieve and RetrieveMultiple plugins
  • Set the plugins to run as current user
  • In plugin code, if current user and owner are different, simply remove the value from the specified field.

NOTE

  • Retrieve plugin works for forms.
  • RetrieveMultiple plugin works for advanced find and views.
  • Find sample plugin code for Retrieve and RetrieveMultiple plugin on google. Modify it according to your above requirement.