[NAV5] Run a form with a predefined filter

ben5000ben5000 Member Posts: 110
Hi I'd like to run a list form from a report with predefined filters. Here is the code I use.
The problem is that this code shows me the list form but with the information of the last record and not the current one.
Component3.SETFILTER(Active,'=%1',Component3.Active::"1");
Component3.SETFILTER("Parent Service Item No.",ParServItemNo); <- this should normally limit the filter on the current record.

//Runs the component list
IF Component3.FINDSET THEN
  CompForm.SETRECORD(Component3);

CompForm.RUNMODAL;
CLEARALL;

I'm new to NAV developing so be indulgent :)

Thx.

Comments

  • krikikriki Member, Moderator Posts: 9,110
    And where is the current record set?

    Better use this code
    // it is best to always put RESET/SETCURRENTKEY to make it clear there are no filters on it (in case there shouldn't)
    Component3.RESET; 
    Component3.SETCURRENTKEY(....);
    
    Component3.SETRANGE(Active,Component3.Active::"1"); // try always to use SETRANGE instead of SETFILTER
    Component3.SETRANGE("Parent Service Item No.",ParServItemNo); <- this should normally limit the filter on the current record.
    
    //Runs the component list
    IF Component3.FINDFIRST THEN ;
    
    FORM.RUNMODAL(0,Component3); // or replace 0 with FORM::"the form you need"
    
    // CLEARALL cleans current object completely. Probably it is not what you want
    

    If it doesn't do yet what you want, check if findfirst takes the correct record by doing a MESSAGE('%1',Component3) after the FINDFIRST.

    Check also if the form doesn't reposition the record through code or properties.

    PS: this is helpful to start: http://www.mibuso.com/howtoinfo.asp?FileID=22
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.