Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
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.)
                }
            }
        }
    }
}

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,688 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,643 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans