Problems reading specific Record from a Table / Navision 4.0

aodaod Member Posts: 54
I want to get an other record from the Sales Shipment Line in the Report "Delivery Note". I created a new Key containing the 3 Fields Document No., Position & Type. I created an new Global in the Report calles ShipLine. And using the Following Code:

ShipLine.setcurrentkey ("Document No.","Position","Type");
If ShipLine.Get ("Document No.","Position",Type::Item) THEN;


I get the Error Message :

"Too many Key Fields where specified, so Sales Shipment Line could not be retrieved. The number of Fields in Primary Key is 2."

What I am doing wrong ?

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    GET always works with the primary key. It does not use the key you selected with SETCURRENTKEY. And the primary key of Sales Shipment Line is "Document No.,Line No.", so it expects only 2 fields.

    Otherwise you need to write your code like this:
    ShipLine.SETCURRENTKEY("Document No.","Position","Type"); 
    ShipLine.SETRANGE("Document No.","Document No.");
    ShipLine.SETRANGE(Position,Position);
    ShipLine.SETRANGE(Type,ShipLine.Type::Item);
    IF ShipLine.FIND('-') THEN;
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • aodaod Member Posts: 54
    Big THX for fast Answer and the very good explaination !

    I will try it as soon as possible.
  • garakgarak Member Posts: 3,263
    "Get" ever use the primary key. When yoe will use an secondary key, you must use setfilter / setrange and find.

    Regards
    Do you make it right, it works too!
  • krikikriki Member, Moderator Posts: 9,118
    garak wrote:
    "Get" ever use the primary key. When yoe will use an secondary key, you must use setfilter / setrange and find.

    Regards
    Always try to use SETRANGE. It is potentially faster than a SETFILTER.

    A good programming practice is:
    recMyRecord.RESET;
    recMyRecord.SETCURRENTKEY("My Key"); // even if it is the primary key
    recMyRecord.SETRANGE(...);
    recMyRecord.SETRANGE(...);
    recMyRecord.SETRANGE(...);
    recMyRecord.SETFILTER(...); // if you can't use a SETRANGE
    IF recMyRecord.FIND('-') THEN
      REPEAT
    
      UNTIL recMyRecord.NEXT = 0;
    
    or in case you don't want to loop the records:
    IF recMyRecord.FIND('-') THEN ...
    
    or even better in 4.00SP1:
    IF recMyRecord.FINDFIRST THEN ...
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.