Hi,
I have an entity called A . All users have user level access on the entity.So, users can access the records only those are created by them.
My requirement is , in some scenarios , when record is created by an user , it has to be shared (give READ access) with some other users based on some condition.
Below is my approach :
1) Register a plugin on create of record.In the plugin, use the PrinciapalAccess() method to share the record
Is there any other approach ? Anything can be done using Access Teams programatically ? Thanks !!
*This post is locked for comments
Hi,
we need to consider below things in this case.
1. Make sure the users to whom you are trying to share should have read privilege(at least at user level)
2. Don't depend on Target, try to retrieve the target record from context. -
Entity target = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet("your fields"));
3. Validate the user context and the user role that must have read privilege on your target record.
4. Plugin context depth. to see if there are any cross scripting that breaking your logic.
Hi
Please make sure the Entity Reference you use in the grant request has the correct logical name
If you still have the same issue, i would try the following
Move your sharing code to a Custom Workflow Activity (CWA) and call this on a background workflow and share and see if that works.
About the user ids, please see below
Initiatinguserid:
This is the user who performs the operation that triggers the plugin. If USER-A creates a record and a plugin is triggered on record create then the Initiatinguserid is USER-A.
Userid:
This contains the "run in user's context" users id that is set as a part of plugin step creation. If the value is not set, then it equivalent to Initiatinguserid
Yes, You can do it by access team.
Thank you Kokulan for the response.But, for time being I followed first approach.But still I am facing below issue
I have a plugin registered (post-operation,synchronous) on create of a custom entity. In the plugin , I am trying to share (using some custom code) the record with another user. My problem is
The code is throwing an exception as "the record with guid = {XXXXX-XXXXX-XXXX} you are trying to share doesn't exist".
This is strange. Because, I registered plugin on post-operation. That means , after the record got created in DB, the plugin triggers.
Any idea why it's throwing exception ?
Also , another thing that I observed while debugging is , context.UserId and context.InitiatingUserId are showing same values through I registered plugin under different user.Here both are showing my Id i.e who is performing create record. Any idea on this ?
Hi
Sharing using plugin would definitely work and, if you want to have a look at a full example please follow the link below
community.dynamics.com/.../crm-2011-2013-share-and-un-share-records-programmatically-c
But I would definitely recommend using an access team template-based approach. When you create the template you can set the permission to be just Read
Please refer to the link below to know the difference between Share and Access Team based approach
community.dynamics.com/.../919501
Please follow the link below to see how you can programmatically add or remove users to an access team of a record
community.dynamics.com/.../add-remove-users-to-access-team-dynamically
If you would like to know more about access team, please refer to the links below
docs.microsoft.com/.../use-access-teams-owner-teams-collaborate-share-information
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156