web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Share Record using a plugin

(0) ShareShare
ReportReport
Posted on by 92
Hello Community,
 
I am facing difficulty in sharing a record using a plugin. I will paste the function below.
The code is not returning any error and executing normally, but the records are not being shared. The user ID and the record ID are passed.
 
I tried to debug the code and it is working fine without any errors, but without sharing.
 
Can someone assist me with any error in my function or another approach for sharing?
 
public void ShareRec(Mission mission, List<RecordToShare> recs)
{
    foreach (var userId in mission.MissionPrev.User)
    {
        var userReference = new EntityReference(/systemuser/, new Guid(userId));
        foreach (var privilege in mission.MissionPrev.Privileges)
        {
            var accessMask = Models.Roles[privilege.Id];
            foreach (var record in recs)
            {
                var recordReference = new EntityReference(record.EntityName, record.RecordId);
                var grantAccessRequest = new GrantAccessRequest
                {
                    PrincipalAccess = new PrincipalAccess
                    {
                        AccessMask = accessMask,
                        Principal = userReference
                    },
                    Target = recordReference
                };
                try
                {
                    service.Execute(grantAccessRequest);
                    // Handle success or logging here if needed
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(ex.Message);
                    // Handle the exception (logging, error handling, etc.)
                }
            }
        }
    }
}
I have the same question (0)
  • Dengliang Li Profile Picture
    Microsoft Employee on at
    Hi,
     
    The OOTB functionality is provided in the Dynamics apps to enable sharing of  records.
    The steps are as follows.

     
    1. Select the record you want to share and choose the Share button in the command bar.

     
    2.  Search for users and add them.

    3.  Grants the user access to records. After completing the grant for all users, click Share.

     
    I hope my answer is helpful to you! If you have any other questions, please feel free to contact me.
     
    Best Regards,
    Dengliang Li
  • MBaba Profile Picture
    92 on at
    Hello,
     
    I am aware of this option. My idea is to automate the process using a certain logic I am following (when creating a record to share its child records automatically to several users). Is there another approach than the one I am using in my code?
     
    Thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 80

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans