Skip to content

RetrieveSharedPrincipalsAndAccessRequest returning User instead of Team

August 7, 2011

This is a strange behaviour I noticed when programmatically assigning or revoking sharing on records: RetrieveSharedPrincipalsAndAccessResponse returns principals that are not readily usable when a record is shared with a team.

For example, see the following code:

/// Remove all shares for a record.
private void Test(string entityName, Guid recordId, IOrganizationService svc)
    // get all the principals that have sharing rights on this record
    RetrieveSharedPrincipalsAndAccessRequest retrieveRequest = new RetrieveSharedPrincipalsAndAccessRequest();
    retrieveRequest.Target = new EntityReference(entityName, recordId);
    RetrieveSharedPrincipalsAndAccessResponse retrieveResponse = (RetrieveSharedPrincipalsAndAccessResponse)svc.Execute(retrieveRequest);

    // for each of those principals, revoke the share
    RevokeAccessRequest revokeRequest = new RevokeAccessRequest();
    revokeRequest.Target = new EntityReference(this.CurrentEntityName, this.CurrentRecordId);
    foreach (PrincipalAccess principal in retrieveResponse.PrincipalAccesses)
        /// if (principal.Principal.LogicalName == "user")
        /// {
        ///     principal.Principal.LogicalName = "team"; // very weird but that's the way it is
        /// }
        revokeRequest.Revokee = principal.Principal;

This code will not work “as is” if the record is shared with a team. The work-around is pretty dirty, and it consists in uncommenting the four highlighted lines in the snippet above.

Untidy little bit, if you ask me.
Alberto “Share the shares” Gemin

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: