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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Share Record using a p...
Power Apps
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.)
                }
            }
        }
    }
}
I have the same question (0)
  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Hello,

    Try to use ModifyAccessRequest instead of GrantAccessRequest.

  • MBaba Profile Picture
    18 on at

    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,306 Most Valuable Professional on at

    Quick question - how's the access mask built?

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard