2

Using the Navision webservices, how can you filter by a date.

i.e. Within a SalesHeader table there is an "ExportedDate". I would like to find all SalesHeaders where the ExportedDate has not been set or were exported on a particular date.

It seems that whenever we set a filter on a date field, then the webservice will either return all rows or no rows.

Billy
  • 21
  • 1
  • 3

2 Answers2

7

This can be done. You have to use the same filter expression as you would use in the Nav Client:

01012011..         would be all dates from 01.01.2011
..01012011         would be all dates to 01.01.2011
01012011..03012011 gets all dates between 01. and 03.
jogojapan
  • 68,383
  • 11
  • 101
  • 131
jaensen
  • 71
  • 1
  • 2
  • I'm dealing with this problem. Our dates in Last_Modified_Date on a page looks like this: 2013-04-09 When doing as explained in the answer nothing is returned: array( 'Field' => 'Last_Date_Modified', 'Criteria' => '20130101..' ) Any clues as to what to do? – nielsstampe May 14 '13 at 11:33
  • In case someone sees this, I have a posted a new question regarding a similar problem here: http://stackoverflow.com/questions/16542364/date-filter-in-microsoft-dynamics-nav-webservice – nielsstampe May 14 '13 at 11:48
1

After publishing page 42 (Sales Order) as a web service in NAV, I added a web reference to the newly created web service in my Visual Studio project. In the C# code, I create a new instance of the service, and tell it to use the default credentials:

SalesOrders_Service salesOrdersService = new SalesOrders_Service();
salesOrdersService.UseDefaultCredentials = true;

Then I instantiate a filter, and set the field and criteria:

SalesOrders_Filter filter = new SalesOrders_Filter();
filter.Field = SalesOrders_Fields.Document_Date;
filter.Criteria = "01-31-14|''"; // specific date (MM-dd-yy) or empty

The filter instance is then added to a new array of SalesOrders_Filters before passing the latter to ReadMultiple:

SalesOrders[] salesOrders = salesOrdersService.ReadMultiple(new SalesOrders_Filter[] { filter }, null, 0);

On my machine, this returns two orders whose Document Date is 31 January 2014, and one order with a blank Document Date.

Jan Hoek
  • 702
  • 5
  • 13