Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Microsoft Dataverse
Unanswered

Share Record using a plugin

(0) ShareShare
ReportReport
Posted on by 18
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.)
                }
            }
        }
    }
}
Categories:
  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Share Record using a plugin

    Quick question - how's the access mask built?

  • MBaba Profile Picture
    18 on at
    Re: Share Record using a plugin

    Hello @a33ik ,

     

    I changed the code as you mentioned, but it still did not work. After checking the shared users for the record, there are still no users.

     

    Mhmdbaba_0-1694065423834.png

     

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Share Record using a plugin

    Hello,

    Try to use ModifyAccessRequest instead of GrantAccessRequest.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Microsoft Dataverse

#1
stampcoin Profile Picture

stampcoin 17

#2
ankit_singhal Profile Picture

ankit_singhal 11 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 9 Super User 2025 Season 1

Overall leaderboard

Featured topics