SETSELECTIONFILTER in Actions

MarkKsMarkKs Member Posts: 12
So, It was asked to me as learning exercise, to create an action in a page to pick a boolean Field based on the selected lines, so for exemple:

3 lines selected = Boolean Field of each line picked.

I created the code of this action in a codeunit to select the lines and fill the boolean field, but only fills the boolean field of the last line, I have 3 selected and the last one gets the boolean field filled. The action code only have 2 lines

CurrPage.SETSELECTIONFILTER(Rec); - This was supposed to make the function below to work on more than 1 line selected.
CUTest.PickLines(No.); - No. is the primary key of the table as parameter to know which lines are selected

Help me understand how should I use SETSELECTIONFILTER in this case and if I have to leave the SETSELECTIONFILTER in the page or in the codeunit with all the code.

P.S - I believe there's no need of showing the CU code here, but If you need to see it just ask.

Best Answer

Answers

  • MarkKsMarkKs Member Posts: 12
    edited 2017-09-18
    Thank you! Just a question when I put the record VAR as parameter in the function, I can detect which lines the user selected by the primary key of the table right? Before I decide to make the main question, I put as parameter, the primary key of the table instead of the record itself. Can you explain me the difference between creating a function with a VAR parameter and with a non-VAR parameter?
  • vaprogvaprog Member Posts: 1,140
    MarkKs wrote: »
    Thank you! Just a question when I put the record VAR as parameter in the function, I can detect which lines the user selected by the primary key of the table right?
    No. Regardless of whether the parameter is VAR or not, the primary key of the passed record reflects the record focused. In the classic client this one did not even have to be selected at all. in the role taylores client it is no longer possible to focus a row without also selecting it.
    MarkKs wrote: »
    Before I decide to make the main question, I put as parameter, the primary key of the table instead of the record itself.
    Because more than one row may be selected, but the primary key denotes exactly one, this approach does not work.
    MarkKs wrote: »
    Can you explain me the difference between creating a function with a VAR parameter and with a non-VAR parameter?
    A VAR parameter is passed by reference. Therefore you can modify the value in the scope of the caller from within the function. For all practical purposes in NAV you can look at this as if a modified version of the VAR parameter is passe back, just as the return value of the function itself.
    With non VAR parameters of type Record, only the field values are passed; exactly the same happens as in an ordinary assignment of record variables (e.g. RecA := RecB;) Therefore, no filters are propagated and you loose the state of the Temporary property. So, if you need any of those, you must use a VAR parameter.

Sign In or Register to comment.