Options

Web Services - Filter on a boolean field

ryancairnsryancairns Member Posts: 40
edited 2012-06-08 in NAV Three Tier
Hi,

I am trying to create a very simple web service and I would like to filter on a boolean field "Active" before calling ReadMultiple. This keeps generating a SoapException: Id 0 was not found in Item object!

Any help would be greatly appreciated - thanks!

//Create a filter
List<PLU_Filter> plufilter = new List<PLU_Filter>();

//Filter on the NAV field - No
PLU_Filter noFilter = new PLU_Filter();
noFilter.Field = PLU_Fields.No;
noFilter.Criteria = "C*";

plufilter.Add(noFilter);

//You can setup multiple filters/search criteria
//Filter on the NAV field - Active
PLU_Filter activeFilter = new PLU_Filter();
activeFilter.Field = PLU_Fields.Active;
activeFilter.Criteria = "True";

plufilter.Add(activeFilter);

//Read the list into an array
PLU[] pluitemlist = pluservice.ReadMultiple(plufilter.ToArray(), null, 100);

Comments

  • Options
    ryancairnsryancairns Member Posts: 40
    Sorry to bump this - but I really thought someone would know the answer to this. If anyone is able to help it would be greatly appreciated. Many thanks, Ryan
  • Options
    KosheKoshe Member Posts: 37
    I've encountered the same behavior if you try to set the filter on a variable instead of a field in the table. Might this be your case?
  • Options
    GoyoGoyo Member Posts: 36
    I have the same problem trying to filter a variable instead of a field. Any ideas how to solve it?
  • Options
    koubekkoubek Member Posts: 84
    This is a example of the filter applied on the BOOLEAN field:
                // collection of the filters
                List<ContactQuestions_Filter> filters = new List<ContactQuestions_Filter>();
                
                // definition of a filter
                ContactQuestions_Filter filter = new ContactQuestions_Filter();            
                filter.Field = ContactQuestions_Fields.Multiple_Answers;
                filter.Criteria = "1";
    
                // add the filter to the collection
                filters.Add(filter);
    
                // first two fields are additional custom parameters and practically do not affect 
                // the functionality of the standard filters
                return ClientWs.ReadMultiple(contactNo, _CenterNo, filters.ToArray(), null, 0);
    

    There is everything all right in my case...
  • Options
    GoyoGoyo Member Posts: 36
    What about filtering a field that isn't part of the table. I want to filter the Job table by Customer Name, but that field doesn't exists in the table. I create a variable and fill it in the OnAfterGetRecord trigger. When I filter that field with the "filter.Field" and "filter.Criteria", i get the SoapException "Id 0 was not found in Job objetct!". Is there a way to do that without creating the field in the table?
  • Options
    koubekkoubek Member Posts: 84
    Goyo wrote:
    What about filtering a field that isn't part of the table. I want to filter the Job table by Customer Name, but that field doesn't exists in the table. I create a variable and fill it in the OnAfterGetRecord trigger. When I filter that field with the "filter.Field" and "filter.Criteria", i get the SoapException "Id 0 was not found in Job objetct!". Is there a way to do that without creating the field in the table?
    What i know you can`t filter on variables in NAV!!! Not in standard and effective way (there are some "tricks" but...). Of course, web services publish a variable as a "field" but it is still just variable that can`t be filtered. This is "native" NAV filtering method. Of course when you retrieve dataset from NAV you can filter this field of the dataset in your client application. But no in NAV directly!!!
Sign In or Register to comment.