Saturday, October 8, 2016

RetrieveSharedPrincipalsAndAccessRequest + Retrieve User Access for Particualr Record MSCRM

Hi All,

(Eg)

Consider there is an Account, which was shared with some users, if you want to know the users in CRM Plugins or console app, use this


Call the below code as

ProcessSharedUser(Service);


public void ProcessSharedUser(IOrganizationService service)
        {
            PrincipalAccess[] sharedUsersOfAccount = getSharedUsersforAccount("account", new Guid(""), service);
            if (sharedUsersOfAccount.Length > 0)
            {
                for (int i = 0; i < sharedUsersOfAccount.Length; i++)
                {
                    getUserList  sharedUsersOfAccount[i].Principal.Id;
                }
            }
  }

 public PrincipalAccess[] getSharedUsersforAccount(string entityName, Guid accountId, IOrganizationService service)
        {
            RetrieveSharedPrincipalsAndAccessRequest retrieveSharedRequest = new RetrieveSharedPrincipalsAndAccessRequest()
            {
                Target = new EntityReference(entityName, accountId)
            };
            RetrieveSharedPrincipalsAndAccessResponse retrieveSharedResponse = (RetrieveSharedPrincipalsAndAccessResponse)service.Execute(retrieveSharedRequest);

            return retrieveSharedResponse.PrincipalAccesses;
        }

No comments:

Post a Comment

Dataverse/MSCRM: Work with Masking Rule

  Introduction: In this blog, we will see how to work with Masking Rule in MSCRM or Dataverse. Issue : I don't want to show the Email va...