sort in RecordRef

trulyjackytrulyjacky Member Posts: 24
edited 2004-03-24 in Navision Attain
Hi,

Is there any way to sort in RecordRef? I know the SETCURRENTKEY in Record can sort the table. But how about RecordRef? I have to use RecordRef because I am not able to determine the table ID at design time.

Comments

  • eromeineromein Member Posts: 589
    Try this:
    Cust.SETCURRENTKEY("Search Name");
    
    Recref.OPEN(DATABASE::Customer);
    Recref.SETTABLE(Cust);
    
    MESSAGE(Recref.CURRENTKEY);
    
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
  • trulyjackytrulyjacky Member Posts: 24
    Thanx eromein. But the problem is that I can't say it must be the Customer table, at design time.

    For example, during run time, the end user may choose from Customer Ledger Entry, Vendor Ledger Entry and Employee Ledger Entry, just as what they want.
    So my RecordRef have to be capable refer to either of these tables and after that, sort that table with Field No.3 (also is Field Index 2), which is either the Customer No., Vendor No. or Employee No.
  • eromeineromein Member Posts: 589
    Could you maybe think of a way to define these things in some kind of settings?

    I made a tool some time ago with which you can find anything in Navision. You can setup relation, conditions, filters and even keys. But these "search rules" are predefines.

    Sample:

    Search from "sales line", if "type = item", for "item", field "search description" where "BOM = yes" with key "search description".

    So as you can see, in my tool, the key is pre-set or pre-defined.

    I think you sould do something like that. Or you could make something that looks-up the best key there is and activated it.

    BTW, here is another way to set a key:
    recref.setview(strsubno('SORTING(%1)',keyname));
    

    Keyname is something like: "field1,field2,field3"

    Here's a little functions that I made which generates keynames:
    GetKeyName(recno : Integer;keyno : Integer) KeyString : Text[250]
    IF (recno = 0) OR (keyno = 0) THEN
      EXIT
    
    recref.open(recno);
    keyref := recref.keyindex(keyno);
    
    IF NOT keyref.ACTIVE THEN
      EXIT;
    
    NumOfKeyFields := keyref.FIELDCOUNT;
    FOR i := 1 to NumOfKeyFields DO BEGIN
      fieldref := keyref.FIELDINDEX(i);
      keystring := STRSUBSTNO('%1%2%3',keystring,separator,fieldref.NAME);
      separator := ',';
    END;
    

    Good luck!
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
  • eromeineromein Member Posts: 589
    btw,

    did you take a look @ http://www.mibuso.com/dlinfo.asp?FileID=276 ?
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
Sign In or Register to comment.