GET-SETRECORD

rhpntrhpnt Member Posts: 688
Maybe a stupid one but I stumbled across this only today. I'm trying to put the cursor in a list form to the line which was found in a variable of the same record. I read the online help, adg and the topics but...

Here is the abstract of my code:
VariableOfRec.SETRANGE(...something...);
VariableOfRec.FINDFIRST;
bla..
bla...
Rec.SETPOSITION(FORMAT(VariableOfRec.GETPOSITION));

I'm doing this in a function of a form (nothing special really). It "kind of" works because the cursor jumps to either one line before or one line after the correct record/line!?

Answers

  • BeliasBelias Member Posts: 2,998
    2 random shots:
    does "rec" variable has filters?
    did you already try to remove the FORMAT from the getposition?(it's useless)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • rhpntrhpnt Member Posts: 688
    edited 2011-09-21
    Hmm... now that you mention it - rec indeed has a filter set...

    FILTERGROUP := 2;
    SETRANGE(SomeField,SomeValue);
    FILTERGROUP := 0;

    ...but the variable of that record has the same one set - double checked. GETPOSITION returns the correct Line No. which complies to the one in Rec but the cursor just won't jump to that one - it prefers to annoy me with fooling around...

    I tryed it without FORMAT and with GETPOSITION(FALSE) - same result.

    The form has a kind of std. NAV worksheet functionality.
  • BeliasBelias Member Posts: 2,998
    What about the record where you should be positioned? does it respect the filter when you apply the SETPOSITION?
    If i remember well, the setposition respects the applied filters and gets nearest record of where you positioned (i think it behaves like a find('<>=') after setting the key values) :-k
    edit: ok, i didn't notice this
    ...but the variable of that record has the same one set - double checked.
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • BeliasBelias Member Posts: 2,998
    Dirty work: add a find('=') after the getposition and see what happens :evil:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • kinekine Member Posts: 12,562
    What about using GET and the primary key from the record variable you used to find the record? I think it is much more clear and clean...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • BeliasBelias Member Posts: 2,998
    Please, someone tell me why I thought VariableRec was a Recordref (thus, no GET instruction possible) :-k
    But regardless, now I want to know if the setposition works correctly :)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • kinekine Member Posts: 12,562
    I think that it works, but it only set the primary key values, not really read the record, thus you need to use FIND('=') to read the data..
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • rhpntrhpnt Member Posts: 688
    Belias wrote:
    Dirty work: add a find('=') after the getposition and see what happens :evil:
    Sorry for the late answer - tried that - same result.
  • rhpntrhpnt Member Posts: 688
    kine wrote:
    What about using GET and the primary key from the record variable you used to find the record? I think it is much more clear and clean...
    Didn't try that one but it sure annoys me that something as easy as GET/SET doesn't work (or is it me?). My experience with this is that as soon as I use SETPOSITION on Rec the cursor does jump but to the wrong line (although GETPOSITION returns the right one - double checked). The online help on this topic is very short with no examples and the ADG doesn't even mention it...

    I'll try some quick and dirty workarounds tomorrow - had enough of CSIDE for today...

    Thanks for the effort guys!
  • rhpntrhpnt Member Posts: 688
    So guys, found the "problem". I was calling the "double entry cursor" function from the OnInsertRecord form trigger. Turns out that you have to consider the "BelowxRec" parameter of that trigger and in turn use NEXT(+ or -1) to get cursor to the right spot.
Sign In or Register to comment.