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

Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...