Quantcast
Channel: Microsoft Dynamics AX - Technical
Viewing all articles
Browse latest Browse all 126

Dynamics 365 - Odata integration (Code snippet)

$
0
0
Dynamics365 integration - Odata:

Guys below code snippet can help you when you play with Odata integration with D365:
public static void customers(Resources context)
{
            DateTime dateTime = new DateTime(2017, 01, 01);
            //Filter the query
            var customers = context.Customers.AsEnumerable().Where(x => x.CreatedDateTime >= dateTime);

            foreach (var customer in customers)
            {
Console.WriteLine(" Customer Account # - {0}, Name - {1}", customer.CustomerAccount, customer.Name);
            }
}

Inserting the record in D365 table (Just a simple example, FYR):
DataServiceCollection<CustomerGroup> customerGroupCollection = new DataServiceCollection<CustomerGroup>(context);

customerGroupCollection.Add(customerGroup);
               
customerGroup.CustomerGroupId = "1000";
customerGroup.Description = "test";
customerGroup.PaymentTermId = "Net30";
context.SaveChanges(SaveChangesOptions.PostOnlySetProperties);

Updating the record can be done using similar code shown below (Just a simple example, FYR):
context.UpdateObject(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);





Viewing all articles
Browse latest Browse all 126

Trending Articles