Esempio n. 1
0
        static void Main(string[] args)
        {
            //CRM credentials
            var password = "";
            var userName = "";
            var crmURL   = "";

            var url = $"Url=https://{crmURL}.api.crm.dynamics.com/api/data/v9.0/; Username={userName}; Password={password}; authtype=Office365";

            CRMRepository   _crm    = new CRMRepository(url);
            RetreiveRequest request = new RetreiveRequest
            {  //Fetch a System user with the email of "*****@*****.**"
                EntityName   = "systemuser",
                FieldsWanted = new string[] { "emailaddress1", "fullname", "statecode" },
                FieldQuery   = new List <FieldMatch>
                {
                    new FieldMatch {
                        FieldtoMatch = "emailaddress1", FielldValue = "*****@*****.**"
                    }
                }
            };

            var getMatchingUsers = _crm.GetRecords(request);

            //Get their status of Active or Inactive
            var firstContactsStatus = ((OptionSetValue)getMatchingUsers.Entities.FirstOrDefault()["statecode"]).Value;
            var secondContactsemail = getMatchingUsers.Entities.Skip(1).FirstOrDefault()["emailaddress1"];
        }
Esempio n. 2
0
        public async Task <D365ServiceResponse> GetRecordById(RetreiveRequest Request)
        {
            if (Request != null)
            {
                string operation             = $"{BaseServiceUrl}{Request.Operation}";
                D365ServiceResponse response = await SendGetRequestAsync(operation);

                return(response);
            }
            return(null);
        }
        public EntityCollection GetRecords(RetreiveRequest request)
        {
            var fieldsToMatch = request.FieldQuery.Select(fq => fq.FieldtoMatch).ToArray();
            var fieldsValue   = request.FieldQuery.Select(fq => fq.FielldValue).ToArray();

            QueryByAttribute querybyattribute = new QueryByAttribute(request.EntityName);

            querybyattribute.ColumnSet = createColumnSet(request.FieldsWanted);

            querybyattribute.Attributes.AddRange(fieldsToMatch);
            querybyattribute.Values.AddRange(fieldsValue);

            EntityCollection retrieved = _serviceProxy.RetrieveMultiple(querybyattribute);

            return(retrieved);
        }
        public async Task <D365ServiceResponse> GetClientByClientNumber(string ClientNumber)
        {
            D365CrudService service       = new D365CrudService();
            RelatedEntity   relatedBranch = new RelatedEntity()
            {
                IdField = Client.BRANCH_ID_FIELD,
                Fields  = new SelectFieldsList(Branch.FIELDS)
            };
            RetreiveRequest request = new RetreiveRequest()
            {
                EntityName      = Client.ENTITY_NAME,
                Fields          = new SelectFieldsList(Client.FIELDS),
                IsAlternateKey  = true,
                IdValue         = ClientNumber,
                KeyFieldName    = Client.ALT_KEY,
                RelatedEntities = new RelatedEntity[1] {
                    relatedBranch
                }
            };

            D365ServiceResponse response = await service.GetRecordById(request);

            return(response);
        }