I am trying to get all Customers created/updated after the value of a DateTime field.
In Dynamics CRM I would periodically call this method:
DateTime LastCheckedCRMAccount { get; set; }
private List<Account> GetCRMAccounts()
{
CRMLinq.ClearChanges(); // otherwise old data may be retrieved
IEnumerable<Account> accounts = from acc in CRMLinq.AccountSet
where acc.ModifiedOn > LastCheckedCRMAccount
select acc;
List<Account> accountList = accounts.ToList();
LastCheckedCRMAccount = DateTime.Now.ToUniversalTime();
return accountList;
}
This is what I have for Dynamics NAV at the moment:
DateTime LastCheckedNAVCustomer { get; set; }
private Customer[] GetNAVCustomers()
{
Customer_Filter filter = new Customer_Filter();
filter.Field = Customer_Fields.Last_Date_Modified;
filter.Criteria = LastCheckedNAVCustomer.ToString("ddMMyyyy") + "..";
Customer[] customers = nCustomer.ReadMultiple(new Customer_Filter[] { filter }, null, 0);
LastCheckedNAVCustomer = DateTime.Now;
return customers;
}
There does not seem to be a "ModifiedOn" field on the NAV customer table; there is a field named "Last Date Modified", but that only contains the date.
I would like to keep CRM Accounts up-to-date with NAV Customers.
Is there a better way to do this?
If you would like to go this way, it is better to add a new DateTime field to Customer table, and fill it with CURRENTDATETIME on insert and on modify. You should also probably need to manage deletes and renames in the Customer table.
Have you considered using the standard CRM to NAV integration via Dynamics Connector?
http://msdn.microsoft.com/en-us/library/gg502460.aspx
There is an implemented functionality in NAV that covers your needs. You might take a look at the "Integration " objects + OnDatabase triggers in Codeunit 1. The main idea here is that all table modify's/inserts/deletes are reflected in the "Integration Record" table which can be used to get a list of Customer records that need to be updated to CRM.