Problem with SETSELECTIONFILTER

zavitzavit Member Posts: 9
There is a problem using the function SETSELECTIONFILTER on a standard subform like the sales lines on a sale order (tablebox on the subform and a link on the form to the subform used), when NO RECORD is selected. Selected means the whole line is highlighted, not to have the cursor on it (the cursor is everytime there). The problem is, after executing the function and removing the filters it sets, NA damages the link view, i.e. you can see all the sales lines on a sales order, even related to another sales headers.

I use this for my delete routine to find out what records on the subform are actually to delete and to handle them accordingly. I found only this way to find out what are the records. Additionally, I can overcome the NA bug on the native DB, but I am still not able to do it on a SQL DB.

Any ideas anybody? Thanks

Comments

  • pdjpdj Member Posts: 643
    I'm not sure I understand the problem. :?
    When using SETSELECTION filter you should almost always do it on a differnent variable than REC. I common mistake with SETSELECTION is that people insert a SomeVar.MARKEDONLY(TRUE) right after. Don't! :-) Just do a SomeVar.FIND('-') and the normal repeat until loop and that's it. Otherwise you get problems when the user doesn't mark any AND when he marks all records.
    If that doens't solve your problem, then please show the code you have in the subform.
    Regards
    Peter
  • zavitzavit Member Posts: 9
    pdj wrote:
    I'm not sure I understand the problem. :?
    When using SETSELECTION filter you should almost always do it on a differnent variable than REC. I common mistake with SETSELECTION is that people insert a SomeVar.MARKEDONLY(TRUE) right after. Don't! :-) Just do a SomeVar.FIND('-') and the normal repeat until loop and that's it. Otherwise you get problems when the user doesn't mark any AND when he marks all records.
    If that doens't solve your problem, then please show the code you have in the subform.

    Thank you for help....

    What I am trying to do is to handle deletion of selected records in the subform with a special logic. For this purpose I essentially need to know in the OnDelete trigger, what are all the records user selected, in another words what are the records the user wants to delete.
    The only possible way to do this I found is to use record marks.

    Do you want to say, it is wrong to "mark" the records using the Rec variable as the parameter for SETSELECTIONFILTER and there is a must to use a helper record variable for this :?: I didn't find anything about such limitation in documentation. :oops:

    Here is the simple way to show you the problem on the standard application sales order lines subform. The task is only to mark the records intended to delete (to be simple, not to delete them really). Just put this code in the OnDeleteRecord trigger in the form 46:
    CLEARMARKS;
    CurrForm.SETSELECTIONFILTER(Rec);
    MARKEDONLY(FALSE);
    EXIT(FALSE);
    

    then try to delete some sales lines using the form 42 Sales Order. It works OK, wenn you really select at least a line, i.e. the selected lines are marked and nothing else is changed. If no line is selected and you try to delete a line (actually the line where the cursor is placed), nothing is marked. That is fine, but what I mean is wrong (maybe a bug :?: ) is if you look on the user filter the NA sets in this case and after you clear this filter, e.g. using Show All (Ctrl+Shift+F7) - the subform link is totaly damaged (I found this out inspecting the view and filters set in the FilterGroup #4). This is a very annoying side effect of using SETSELECTIONFILTER(Rec).

    I tried your recommendation and I found it very usefull and indirectly solving my problem. :lol: The idea is not to use the SETSELECTIONFILTER for marking primary, but only secondary, and instead of this to use it primary for filtering, because it sets combinations of different kind of filters on a record variable while the filtered result set corresponds to the set of selected records on the GUI. :idea: Is it correct?
  • pdjpdj Member Posts: 643
    Now I think I know what you want and where the problem is. :idea:
    My idea about the code behind the function is like this:
    SETSELECTIONFILTER(VAR SL : Record "Sales Line")
    SL.COPY(Rec);
    CASE <situation> OF
      <situation>::"all blue lines":
        BEGIN
          ;
        END;
      <situation>::"more than one blue line":
        BEGIN
          SL.CLEARMARKS;
          <MARK all "blue" lines>
          SL.MARKEDONLY(TRUE);
        END;
      ELSE BEGIN
        SL.RESET; // This line is the problem!
        SL.SETRECFILTER;
      END;
    END;
    
    For some reason it does a SL.RESET which deletes the filters in the other filtergroups. Does this match your investigation?
    However; this doesn help solving you problem :( but maybe the understanding of the function enables someone to find a solution 8)

    Hmm, I might have an idea! I'll get back to you if I get it to work :-)
    Regards
    Peter
  • pdjpdj Member Posts: 643
    Try putting this function on the form and call it instead of CurrForm.SETSELECTIONFILTER: (Just adjust the variables 8) )
    MySETSELECTIONFILTER(VAR "Standard Text" : Record "Standard Text")
    CurrForm.SETSELECTIONFILTER(LocStdTxt);
    IF LocStdTxt.MARK THEN
      "Standard Text".COPY(LocStdTxt)
    ELSE BEGIN
      "Standard Text".COPY(Rec);
      "Standard Text".CLEARMARKS;
      LocStdTxt.FIND('-');
      REPEAT
        "Standard Text" := LocStdTxt;
        "Standard Text".MARK(TRUE);
      UNTIL LocStdTxt.NEXT = 0;
      "Standard Text".MARKEDONLY(TRUE);
    END;
    
    Regards
    Peter
  • ioneluckaionelucka Member Posts: 2
    I Have a problem regarding the setselectionfilter table. I have a form that contains 4 tableboxes, all of them for the same table. Depending on a text box filter one of the tablebox is activated. But in this case it seems to me that setselectionfilter is not working. Did anyone have this problem?
  • BeliasBelias Member Posts: 2,998
    ionelucka wrote:
    I Have a problem regarding the setselectionfilter table.
    ...Selectionfilter is not a table
    ionelucka wrote:
    I have a form that contains 4 tableboxes, all of them for the same table. Depending on a text box filter one of the tablebox is activated.
    i don't think that setselectionfilter is what you need (if i understood you)...you can add all tableboxes at design time and show them according to your conditions
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • ioneluckaionelucka Member Posts: 2
    I know that setselectionfilter is not a table. I was just thinking on my message and I didn't pay attention on my writing.

    So I don't have a problem with showing the tableboxes.
    My problem is: If I select to lines in the current tablebox, with setselectionfilter I still get only the line with the arrow.
    If I have only one table box the setselectionfilter it's working just fine, but If I have more than one tablebox on the same table the setselection filter it's not working
  • MommsenMommsen Member Posts: 2
    This topic is quite old, but since there still is the same bug, even in NAV 2013, here my conclusion:
    It is simply not working. SETSELECTIONFILTER only works if the initial Action is startet from within the subform!
    The only (dirty and annoying) workaround is to use sendkeys, to trigger an action on the subform, and then store the selection, and either do the required actions within the subform/page, or -again- trigger an action in the mainform/page via sendkeys.

    Stupid BUG! Over 10 years old! In rare cases it even returns MORE selections than actually selected... Sendkeys workaround is messy and slow...
  • vaprogvaprog Member Posts: 1,141
    Are you referring to the problem the initial poster had (zavit) or the problem the hitchhiker, ionelucka had.

    Concerning the former, there is no bug. It works exactly as pdj described in his pseudo-code, which does correspond to what is documented.

    Concerning the latter, I cannot reproduce it (I tried with 2 subforms only). ionelucka probably queried the wrong subform.
    momsen wrote:
    It is simply not working. SETSELECTIONFILTER only works if the initial Action is startet from within the subform!
    The only (dirty and annoying) workaround is to use sendkeys, to trigger an action on the subform, and then store the selection, and either do the required actions within the subform/page, or -again- trigger an action in the mainform/page via sendkeys.
    I don't understand. SETSELECTIONFILTER is no function on it's own. You can only call it as CurrForm.SETSELECTIONFILTER. Obviously you need to do this from within the subform, if you want to get the selections that had been made in the subform. And you can call functions in the subform and pass (VAR-) parameters, so you can pass information both ways. No need to do any sendkeys. From where you trigger the call to the function in the subform that eventually executes CurrForm.SETSELECTIONFILTER does not matter.
  • MommsenMommsen Member Posts: 2
    @vaprog
    I refer to CurrPAGE.SETSELECTIONFILTER on the RTC.
    For example, I created a function testSelection which does nothing but MESSAGE the COUNT of the result of CurrPAGE.SETSELECTIONFILTER. Then I created one action on the SubPage with this function, and one action on the MainPage.
    When I then call the action on the subpage it works as expected, but when the MainPage Action calls the same function on the SubPage, the result mostly is 0! Sometimes its not 0, but even if you call it twice, without changing the selection, the result most probably will be 0 again.
    So the workaround is to call the subpage action from mainpage via sendkeys, to trigger the subform action, which than again would have to sendkey an action to the mainpage, because there is no way (I know of) to call a function in a parent page.
    Its just plain annoying... kills the usability for many pages I have to design. The sendkeys method is dirty, slow and it´s also annoying that shortcuts and sendkeys kind of collide sometimes. For example I designed a page which joins lines in a subform via ctrl-1, and the most common action afterwards is also using a hotkey like ctrl-2, the user has to release the ctrl key between ctrl-1 and ctrl-2 (otherwise its just a '2' wich overwrites contents of the current cell and the user has to esc to undo) ... Explain that to the user...its really really terribly annoying!
Sign In or Register to comment.