I am getting this error "NAV Server time and CRM Server time may not be in sync or there is no data for the submitted date"while running my ms dynamics nav-crm connector application in .net. Has anyone come across this error or know how to rectify this.... The code down below is used for this connector..not the entire code however.,.,This I believe is occuring while trying to connect tot he CRM in the
getOrders function
using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel.Description; using System.IO; using System.Xml; using System.Xml.Linq; using System.Security; using System.Runtime.InteropServices; using System.DirectoryServices.AccountManagement; using System.ServiceModel; //crm using Microsoft.Xrm.Sdk.Client; using Microsoft.Xrm.Sdk.Discovery; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Messages; using EssaeXrm; namespace Wpf_to_CRM { class config { public Uri DiscoveryUri ; public Uri OrganizationUri ; DiscoveryServiceProxy discserviceProxy ; OrganizationServiceProxy orgserviceProxy ; public ClientCredentials clientcred ; public DateTime datm; string usr, pwd, reg, organisation , crmver; public ClientCredentials devicecred ; public void usrpwd(string x, string y , string z , string c) { this.usr = x; this.pwd = y; this.reg = z; this.crmver = c; } public virtual ClientCredentials GetCredentials() { ClientCredentials credentials = new ClientCredentials(); credentials.UserName.UserName = usr; credentials.UserName.Password = pwd; return credentials; } protected virtual ClientCredentials GetDeviceCredentials() { return Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice(); } public OrganizationDetailCollection DiscoverOrganizations(IDiscoveryService service) { if (service == null) throw new ArgumentNullException("service"); RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest(); RetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)service.Execute(orgRequest); return orgResponse.Details; } public OrganizationDetailCollection allorgs() { try { this.clientcred = this.GetCredentials(); this.devicecred = this.GetDeviceCredentials(); this.DiscoveryUri = new Uri(String.Format("https://{0}.{1}.dynamics.com/XRMServices/2011/Discovery.svc", this.crmver, this.reg)); using (discserviceProxy = new DiscoveryServiceProxy(DiscoveryUri, null, clientcred, devicecred)) { OrganizationDetailCollection allorg = this.DiscoverOrganizations(discserviceProxy); return allorg; } } catch { return new OrganizationDetailCollection(); } } public List<string> orgdetail() { OrganizationDetailCollection orgs = this.allorgs(); List<string> orgname = new List<string>(); int i = 0; while(i < orgs.Count) { orgname.Add(orgs[i].UrlName); i++; } return orgname; } public void selectedorg(string retorg , DateTime datme) { this.organisation = retorg; this.datm = datme; } public DataTable querylist() { try { //Organization URL OrganizationUri = new Uri(String.Format("https://{0}.api.{1}.dynamics.com/XRMServices/2011/Organization.svc", this.organisation, this.reg)); using (orgserviceProxy = new OrganizationServiceProxy(OrganizationUri, DiscoveryUri, clientcred, devicecred)) { // This statement is required to enable early-bound type support. orgserviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); IOrganizationService orgservice = (IOrganizationService)orgserviceProxy; using (ServiceContext svcContext = new ServiceContext(orgserviceProxy)) { DateTime d = datm.AddDays(1); //DateTime d1 = d.AddDays(-1); //DateTime d2 = d.AddDays(1); var query = from a in svcContext.SalesOrderSet join b in svcContext.AccountSet on a.CustomerId.Id equals b.Id where a.SubmitDate < d && a.SubmitDate > datm && a.StatusCode == 3 select new { A = a, B = b }; //StreamWriter sw = new StreamWriter(@"C:\excelfile\excel.csv", true); DataTable dt = new DataTable(); dt.Columns.Add("SO Id"); dt.Columns.Add("Order Number"); dt.Columns.Add("Name"); dt.Columns.Add("Submitted Date"); dt.Columns.Add("Customer"); dt.Columns.Add("Total Tax"); dt.Columns.Add("Total Line Item Amount"); dt.Columns.Add("Total Amount"); dt.Columns.Add("Structure"); foreach (var e in query) { dt.Rows.Add(e.A.Id.ToString(), e.A.OrderNumber, e.A.Name, e.A.SubmitDate, e.B.AccountNumber, e.A.TotalTax, e.A.TotalLineItemAmount, e.A.TotalAmount, e.A.new_Structure.Name); //sw.WriteLine(e.A.Id.ToString() + "," + e.A.OrderNumber + "," + e.A.Name + "," + e.A.TotalAmount.ToString() + "," + e.A.CustomerId.Id.ToString() + "," + e.B.AccountNumber + "," + e.B.AccountId.Value.ToString() + "," + e.B.AccountId.ToString() + "," + e.B.Name); } //sw.Close(); return dt; } } } catch { return new DataTable(); } } public virtual ClientCredentials newcred(string usr, string pass) { ClientCredentials cred = new ClientCredentials(); cred.UserName.UserName = usr; cred.UserName.Password = pass; return cred; } public DataTable prodquery(List<string> str) { DiscoveryUri = new Uri(String.Format("https://{0}.{1}.dynamics.com/XRMServices/2011/Discovery.svc", str[1], str[4])); OrganizationUri = new Uri(String.Format("https://{0}.api.{1}.dynamics.com/XRMServices/2011/Organization.svc",str[0],str[4])); this.newcred(str[2],str[3]); using(OrganizationServiceProxy orgprox = new OrganizationServiceProxy(OrganizationUri,DiscoveryUri,this.newcred(str[2],str[3]),this.GetDeviceCredentials())) { // This statement is required to enable early-bound type support. orgprox.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); using(ServiceContext svCon = new ServiceContext(orgprox)) { Guid ID = new Guid(str[5]); var prodq = from e in svCon.SalesOrderDetailSet join d in svCon.ProductSet on e.ProductId.Id equals d.Id where e.SalesOrderId.Id == ID select new { E = e, D = d }; DataTable prdet = new DataTable(); prdet.Columns.Add("Product Name"); prdet.Columns.Add("Quantity"); prdet.Columns.Add("Unit Price"); foreach(var q in prodq) { prdet.Rows.Add(q.D.ProductNumber,q.E.Quantity,q.E.PricePerUnit); } return prdet; } } } public DataTable getOrders(DateTime datm) { try { DiscoveryUri = new Uri(String.Format("https://{0}.{1}.dynamics.com/XRMServices/2011/Discovery.svc", "dev", "crm5")); OrganizationUri = new Uri(String.Format("https://{0}.api.{1}.dynamics.com/XRMServices/2011/Organization.svc", "essaetechnologyspvtlimited", "crm5")); using (OrganizationServiceProxy orgproxy = new OrganizationServiceProxy(OrganizationUri, DiscoveryUri, this.newcred("essaecrm@live.in", "Essae@123"), this.GetDeviceCredentials())) { orgproxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); using (ServiceContext svcContext = new ServiceContext(orgproxy)) { DateTime d = datm.AddDays(1); var query = from a in svcContext.SalesOrderSet join b in svcContext.AccountSet on a.CustomerId.Id equals b.Id join c in svcContext.SystemUserSet on a.OwnerId.Id equals c.Id where a.SubmitDate < d && a.SubmitDate > datm && a.StatusCode == 3 select new { A = a, B = b, C = c }; DataTable dt = new DataTable(); dt.Columns.Add("SO Id"); dt.Columns.Add("Order Number"); dt.Columns.Add("Name"); dt.Columns.Add("Submitted Date"); dt.Columns.Add("Customer"); dt.Columns.Add("Address Contact"); dt.Columns.Add("Ship to Address 1"); dt.Columns.Add("Ship to Address 2"); dt.Columns.Add("Structure"); dt.Columns.Add("Ship to City"); dt.Columns.Add("Purchase Order No"); dt.Columns.Add("Purchase Order Date"); dt.Columns.Add("Remarks"); dt.Columns.Add("SO Series"); dt.Columns.Add("Core details"); dt.Columns.Add("Salesperson Code"); dt.Columns.Add("Request Delivery Date"); string SOseries = String.Empty; string CoreDetails = String.Empty; foreach (var e in query) { try { switch (e.A.new_SOseries) { case 100000000: SOseries = "HO"; break; case 100000001: SOseries = "LD"; break; case 100000002: SOseries = "MH"; break; case 100000003: SOseries = "AP"; break; default: SOseries = ""; break; } switch (e.A.new_CoreDetails) { case 100000000: CoreDetails = "1\""; break; case 100000001: CoreDetails = "0.5\""; break; case 100000002: CoreDetails = "40mm"; break; case 100000003: CoreDetails = "3\""; break; default: CoreDetails = ""; break; } dt.Rows.Add(e.A.Id.ToString(), e.A.OrderNumber, e.A.Name, e.A.SubmitDate, e.B.AccountNumber, e.A.BillTo_ContactName, e.A.ShipTo_Line1, e.A.ShipTo_Line2, e.A.new_Structure.Name, e.A.ShipTo_City, e.A.new_PONumber, e.A.new_PurchaseOrderDate, e.A.Description, SOseries, CoreDetails, e.C.dynamics_erpsystemuserid.Name, e.A.RequestDeliveryBy); } catch { } } return dt; } } } catch { return new DataTable(); } } } }