Dynamics 365 - Odata integration (Code snippet)
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);
|
Valuable post useful for everyone.Keep on sharing.
ReplyDeleteMS Dynamics AX Online Training