web-servicessoapmicrosoft-dynamicsdynamics-nav-2009

How to apply Entity_Filter as OR in Dynamics NAV WebService


I am consuming a Dynamics NAV 2009 WebService (SOAPish). Specific I am talking about the ReadMultiple method MSDNA

The filterArray takes an array of Entity_Filter objects. Each Entity_Filter has a Field and Criteria property.

Now I want to know, how I can apply the filters as OR not and.

For Example I am passing two filters:

Entity_Filter { Field: "Name", Criteria: "*banana*" }
Entity Filter { Field: "Color", Criteria: "yellow"}

If I send this to the ReadMultiple I get all entries that have "banana" as part of the name AND the color yellow. What do I have to do, to get all Entries that have "banana" as part of the name OR the color yellow?


Solution

  • Unfortunately, there is no way to apply an 'OR' filter on a record. ReadMultiple method applies filters the same way C/AL methods SETFILTER or SETRANGE do. It has to be done in two separate requests.

    On the second thought, you can do it in a single request, but with an OData service using Linq:

    NAV nav = new NAV(new Uri("http://ServerName:Port/DynamicsNAV71/OData/Company('Your Company Name')"));
    nav.Credentials = CredentialCache.DefaultCredentials;
    var items = from i in nav.ItemsList where i.Name.Equals("Banana") || i.Color.Equals("Yellow") select i;
    

    Where 'ItemsList' is an OData web service of type 'Page'