Using GET with RecordRef


Hi

I'm new to this RecordRef, FieldRef, RecordID functionality in Navision 3.60 so perhaps this is trivial questions, but here goes anyway... [:)]

My goal is to get one record from a table and be able to access the fields as an array.

Here's my code so far:

RecordRef.open(27); // Item Table
// Get one specific item
RecordRef.GET('1000'); // error - expects a recordID

// 'for'-loop though the fields using
// the RecordRef.FIELDINDEX function for this job
// possible change of some fields.

RecordRef.MODIFY; // save changes to record

So i guess my real question is how to use the recordID together with recordRef [?]

Any links to information about RecordRef, FieldRef, RecordID would also be nice... [:)]

Thanks in advance,

Rasmus Torpe
  • There is a (very) small document on the ftp server of Navision...
  • Rasmus,

    maybe you want to look how Navision/MBS itself is using the RecRef.
    One problem they have is the change log. It is not working if you make changes to records in codeunits. This is where/why I found some infos:

    MBS uses the RecRef/xRecRef in Codeunit 103 Cust. Entry-Edit to create their entries in the change log.
    You will find a function call to Codeunit 423 Change Log Management where they are extensively use the RecRefs....
    Interesting functions:
    LogInsertion
    LogModification
    LogDeletion
  • Hello Rasmus

    Here is a code example of how to find and change a record using RecordRef. Instead of using GET you can set filters and find records.
    RecRef.OPEN(27);
    FldRef := RecRef.FIELD(1); // Item."No."
    FldRef.SETRANGE('70000');
    RecRef.FIND('-');
    FldRef := RecRef.FIELD(3); // Item.Description;
    FldRef.VALUE('My own description');
    RecRef.MODIFY;


    Here is a code example of how to loop through the fields.
    RecRef.OPEN(27);
    FldRef := RecRef.FIELD(1); // Item."No."
    FldRef.SETRANGE('70000');
    RecRef.FIND('-');
    FOR i := 1 TO RecRef.FIELDCOUNT DO BEGIN
    FldRef := RecRef.FIELDINDEX(i);
    CASE FldRef.NAME OF // Or you can use a case on FldRef.NUMBER
    'Description': MESSAGE('%1 is %2.',FldRef.CAPTION,FldRef.VALUE); // Or do some changes
    'Unit Cost': MESSAGE('%1 is %2.',FldRef.CAPTION,FldRef.VALUE);
    END;
    END;


    Hope these little examples helps.
    I have found the filterfunctions GETVIEW and SETVIEW very useful to set filters on RecordRefs. These functions are available on both RecordRefs and Records.

    /Magnus
  • Trust me, don't put to much time into this right now. Just wait for some new releases. There are some strange and really weird bugs in this functionality at this moment. And don't even try to open a recref in the onpredataitem and use it in the onaftergetrecord of a report.
  • Hello

    Thank you for all the replies! [:)]

    The solution I am using now is the RecordRef.SETPOSITION filter function in the following way:

    RecordRef.OPEN(27);
    RecordRef.SETPOSITION('No. = CONST('1000')');
    if RecordRef.FIND then
    REPEAT
    ....
    UNTIL RecordRef.NEXT = 0;

    the only reason I am using this approch for now is because it is short to write... [;)]
  • If you create a function inwhich your parameters are tableno and the key of this table, you could do something like this.

    recreffunc(database::item,item.getposition); // Call function

    recreffunc(tableno : integer, tableposition : text 30);
    begin
    RecordRef.OPEN(tableno);
    RecordRef.SETPOSITION(tableposition);
    end
Related
Recommended