1

I'm building a Lightswitch application using MS Visual Studio 2013. As part of this I access data through an OData url (referencing a dynamics nav project) which does not seem to want to pick up the company data in the url. (It does without it). However then within Visual Studio I only see the column headers and no data. When I debug I get the following error message:

"Cannot process the request because the default Microsoft Dynamics NAV company cannot be found. You can specify a default company in the service configuration file, or specify one for each tenant, or you can add a query string in the form of "company=[name]". You can see the available companies by accessing the default OData web service, Company. For more information, see "OData Web Services" in Help."

For example: (OData url): localhost:7048/DynamicsNAV70/OData/Company('CRONUS%20International%20Ltd.')/SalesOrder

But only viewable as: localhost:7048/DynamicsNAV70/OData/ and then selecting SalesOrder

My question is, what config files are they refering to? (Visual studio?If so how do I add the company name?) "OData Web Services" in Help was of no use.

1 Answers1

2

I had to add additional code within Visual Studio to reference the company, for example:

ServiceReference1.NAV nav = new ServiceReference1.NAV(new Uri("http:...../OData/Company('company_name')/"));

nav.Credentials = new System.Net.NetworkCredential("user", "password", "domain");

  • Cool - thinking about how most of the Dynamics family are designed for multi-tenancy these days, that makes a lot of sense. :) GL with the rest of the build! – Ozziemedes Nov 13 '14 at 14:17
  • Thank you! Next up..... converting the dates from OData to give up the number of the week that year. –  Nov 13 '14 at 14:24
  • Try the following in your javascript code to get the OData date converted to a JavaScript date: var date='/Date(1291548407008)/'; var substringedDate = date.substring(6); //substringedDate= 1291548407008)/ var parsedIntDate = parseInt(substringedDate); //parsedIntDate= 1291548407008 var date = new Date(parsedIntDate); // parsedIntDate passed to date constructor I would usually then have something like a date dimension table that I can pass a real date to in a where clause and bring back a week of year value. – Ozziemedes Nov 13 '14 at 15:08
  • The tricky bit with that process is defining your week boundaries. Do you count from the first full week of the year? Or from the first *part* of a week in the year. Does Dynamics NAV have a time dimension table you can use in a separate OData query to look up the week as defined in NAV? – Ozziemedes Nov 13 '14 at 15:10
  • Thank you @Ozziemedes! I will give it a try. I cant really do too much work with the OData string, so will have to do all the heavy lifting in Visual Studio. My week definition is the [ISO 8601 Definition](http://www.tuxgraphics.org/toolbox/calendar.html) used in Europe which counts week 1 as the first week of the year with a Thursday. –  Nov 14 '14 at 08:12
  • Cool - that makes it easier. Step the first: Identify the start date of week 1 (just count on up to the first Thursday using the appropriate functions on the DateTime type. Then get a date diff (in days) between each target date and the start of the first week. Then, do an integer div to get the week number. (Keep in mind that you might need to add 1 to ensure that the first week is considered week 1, not week 0.) – Ozziemedes Nov 16 '14 at 12:50