コード例 #1
0
        public override CrmService CreateCrmServiceInstance()
        {
            var service = new CrmService($"AuthType=ClientSecret;Url='{_loginInfo.Url}';ClientId='{_clientId}';ClientSecret='{_clientSecret}';RequireNewInstance=True");

            service.CallerId = GetImpersonatingUser(service);
            return(service);
        }
コード例 #2
0
        private Guid GetImpersonatingUser(CrmService service)
        {
            var queryResult = service.RetrieveMultiple(new QueryExpression(SystemUser.EntityLogicalName)
            {
                NoLock   = true,
                TopCount = 1,
                Criteria =
                {
                    Conditions =
                    {
                        new ConditionExpression(SystemUser.Fields.UserName, ConditionOperator.Equal, _loginInfo.Username)
                    }
                }
            });

            if (queryResult.Entities.Count == 0)
            {
                throw new TestExecutionException(Constants.ErrorCodes.USER_NOT_FOUND);
            }
            return(queryResult.Entities[0].Id);
        }