Get value by FieldNo.

santiagonavsantiagonav Member Posts: 6
Hi, sorry for my English, that's not my language. I'll try to explain as best as possible.

I'm trying to retrieve a value from current record (Rec), but I need to recover the value of a particular field (this information I get from another table, id field and name field).

I tried to do through RecRef and Field Ref, but I can not position the cursor on the desired record (Rec). I have the feeling that there is an easier way.

I hope I explained well. Any help would be welcome.

Regards.

Comments

  • krzychub83krzychub83 Member Posts: 120
    If you have only the field no., then you have to do it by recordref. Check out codeunit 423 (Change Log Management) for details how to user references.
  • santiagonavsantiagonav Member Posts: 6
    Solved using SETTABLE in RecordRef.


    recRF.OPEN(recObjet.ID,FALSE);
    recRF.SETTABLE(Rec);
    recRF.FINDFIRST;

    fldRef := recRF.FIELD(3); //<---Set the Field Number

    MESSAGE(FORMAT(fldRef.VALUE));
  • santiagonavsantiagonav Member Posts: 6
    I thought it worked, but it is not.

    When I called from a Card Form (without filters), I am getting data from the first record.

    RecObject.ID is the value of the current table.
  • BeliasBelias Member Posts: 2,998
    why do you want to do this?
    why do you use recordref and fieldref instead of declaring a table variable and to a simple
    message(format(mytable.myfield));
    
    :?:
    moreover, you should use GETPOSITION and SETPOSITION (use NAV online help for more info about these functions) to achieve what you need.
    if you do a FINDFIRST without filters like you did, what can you expect?the first record in the table, i guess! :wink:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • santiagonavsantiagonav Member Posts: 6
    Hi, thanks for spending your time to help me.

    I can not create a simple variable, because the table I find out at runtime.

    I will investigate the functions and setPosition getPosition (never had used before.)

    With FindFirst, I thought that would be placed in the current record, but I was wrong.

    Thank you
  • mkbmkb Member Posts: 7
    You have a record as your Source and want to get the value of a field, right?
    RecRef.GETTABLE(Record);
    FRef := RecRef.FIELD(FieldNo);
    There's your FRef.VALUE, no need to FIND the record ...

    On a sidenote: FINDFIRST will move to the first record. If you have the PK-Values set (e.g. by SETPOSITION) you can use FIND('=') to fetch the record.

    Cheers,
    mkb
Sign In or Register to comment.