Tuesday, March 31, 2015

Dynamics NAV 2013 - How to display a related field from another table on a page

On the CAL code for the Page, use this code to display the Barcode from the Barcode Table next to the items on my current table that only has populated Item no. and a blank field emptyBarcode with no data.

We use the emptyBarcode field as a variable to store the Barcode value we find.
Once we populate the emptyBarcode in the CAL code, the value is displayed on the page in the emptyBarcode field

//-------------------------------------------------------------------
OnAfterGetRecord()

BarcodeRec.SETCURRENTKEY("BarcodeItem No.");
BarcodesRec.SETRANGE("BarcodeItem No.","Item No.");
BarcodesRec.SETRANGE("Show for Item",TRUE);
IF BarcodesRec.FIND('-') THEN
  emptyBarcode := BarcodesRec."Barcode No."
ELSE BEGIN
  BarcodesRec.SETRANGE("Show for Item");
  IF BarcodesRec.FIND('-') THEN
    emptyBarcode := BarcodesRec."Barcode No."
  ELSE
    emptyBarcode := '';
END;
//------------------------------------------------------------------------


Sample of how to cycle through records and get a sum
//-------------------------------------------------------------

SL.SETRANGE("Document No.","No.");
SL.SETRANGE("Document Type","Document Type");
IF SL.FIND('-') THEN
  REPEAT
    Docamt:= Docamt + SL.Amount
  UNTIL SL.NEXT <= 0;

SL.Amount = Docamt;
SL.MODIFY;
//----------------------------------------------------------------
CAL Globals:

  • BarcodesRec
    • Datatype: Record
      • Subtype (Table): Barcodes

No comments:

Post a Comment