如何将Incoming Lot Table的LineReferenceNumber传递至关联行页面并赋值
需求描述
开发系统时,需要将Incoming Lot Table中的LineReferenceNumber传递至Incoming Lot Lines Page,并自动填充到Incoming Lot Line Tables的LotReference字段,实现新增行与对应入库批次页面的关联。
现有代码
1. Incoming Lot Line Tables 表(50101)
table 50101 "Incoming Lot Line Tables" { Caption = 'Incoming Lot Line Tables'; DataClassification = ToBeClassified; fields { field(1; "LineID"; Code[38]) { Caption = 'LineID'; } field(2; "LotReference"; Code[38]) { Caption = 'LotReference'; } field(3; "Metal Code"; Enum "MetalTypes") { Caption = 'Metal Code'; } field(4; Weight; Decimal) { Caption = 'Weight'; trigger OnValidate() var WeightConversion: Codeunit "Weight Conversion"; begin Rec."OZ T C" := WeightConversion.ConvertToOZ(Rec.Weight, Rec."Weight Standard"); end; } field(5; "Weight Standard"; Enum "Weight Standards") { Caption = 'Weight Standard'; trigger OnValidate() var WeightConversion: Codeunit "Weight Conversion"; begin Rec."OZ T C" := WeightConversion.ConvertToOZ(Rec.Weight, Rec."Weight Standard"); end; } field(6; "OZ T C"; Decimal) { DecimalPlaces = 0 : 5; Editable = false; } field(7; "Live Price"; Decimal) { Caption = 'Live Price In USD'; } } keys { key(PK; "LineID") { Clustered = true; } } trigger OnInsert() var IDGeneration: Codeunit "ID Generation"; begin if "LineID" = '' then "LineID" := IDGeneration.GenerateUniqueID(); end; }
2. Incoming Lot Table 表(50100)
table 50100 "Incoming Lot Table" { Caption = 'Incoming Lot Table'; DataClassification = ToBeClassified; fields { field(1; "Lot No."; Code[20]) { Caption = 'Lot No.'; } field(2; "Client Name"; Text[45]) { Caption = 'Client Name'; } field(3; "Client Phone No."; Text[10]) { Caption = 'Client Phone No.'; } field(4; "Sent To Lab"; Boolean) { Caption = 'Sent To Lab'; } field(5; "OZ T"; Decimal) { } field(6; "LineReferenceNumber"; Code[38]) { } } keys { key(PK; "Lot No.") { Clustered = true; } } trigger OnInsert() var IDGeneration: Codeunit "ID Generation"; begin if "LineReferenceNumber" = '' then "LineReferenceNumber" := IDGeneration.GenerateUniqueID() end; }
3. Incoming Lot 页面(50102)
page 50102 "Incoming Lot" { PageType = Document; SourceTable = "Incoming Lot Table"; ApplicationArea = All; Caption = 'Incoming Lot'; UsageCategory = Documents; layout { area(Content) { group(General) { Caption = 'General'; field("Lot No."; Rec."Lot No.") { ToolTip = 'Specifies the value of the Lot No. field.', Comment = '%'; Editable = true; NotBlank = true; } field("Client Name"; Rec."Client Name") { ToolTip = 'Specifies the value of the Client Name field.', Comment = '%'; Editable = true; NotBlank = true; } field("Client Phone No."; Rec."Client Phone No.") { ToolTip = 'Specifies the value of the Client Phone No. field.', Comment = '%'; Editable = true; } field("Sent To Lab"; Rec."Sent To Lab") { ToolTip = 'Specifies the value of the Sent To Lab field.', Comment = '%'; Editable = true; } field(SystemCreatedAt; Rec.SystemCreatedAt) { ToolTip = 'Specifies the value of the SystemCreatedAt field.', Comment = '%'; Editable = true; } } group("Lot Information") { part(Lines; "Incoming Lot Lines") { ApplicationArea = All; SubPageLink = "LotReference" = FIELD("LineReferenceNumber"); } } } } actions { area(Processing) { action("Delete Data") { Caption = 'Delete All Lots'; ApplicationArea = All; trigger OnAction() begin DeleteAllLots(); end; } action("Upload Lot") { Caption = 'Upload Lot'; ApplicationArea = All; trigger OnAction() begin UploadLot(); end; } } } procedure DeleteAllLots() var IncomingLotRec: Record "Incoming Lot Table"; begin IncomingLotRec.DeleteAll(); Message('All lots have been deleted.'); end; procedure UploadLot() var IncomingLotRec: Record "Incoming Lot Table"; begin IncomingLotRec.Init(); IncomingLotRec."Client Name" := Rec."Client Name"; IncomingLotRec."Client Phone No." := Rec."Client Phone No."; IncomingLotRec."Sent To Lab" := Rec."Sent To Lab"; IncomingLotRec."LineReferenceNumber" := Rec."LineReferenceNumber"; IncomingLotRec.Insert(false, true); end; }
4. Incoming Lot Lines 页面(50124)
page 50124 "Incoming Lot Lines" { PageType = ListPart; SourceTable = "Incoming Lot Line Tables"; ApplicationArea = All; Editable = true; layout { area(Content) { repeater(Group) { field("Metal Code"; Rec."Metal Code") { ApplicationArea = All; Editable = true; } field("Weight Standard"; Rec."Weight Standard") { ApplicationArea = All; } field("Weight"; Rec."Weight") { ApplicationArea = All; } field("OZ T C"; Rec."OZ T C") { ApplicationArea = All; DecimalPlaces = 0 : 5; Editable = false; } } } } trigger OnOpenPage() begin Rec.SetFilter("Metal Code", 'PLT'); end; }
实现步骤
只需修改Incoming Lot Lines页面,通过Parent属性获取父页面的LineReferenceNumber值,在新增行时自动赋值。
修改后 Incoming Lot Lines 页面代码
page 50124 "Incoming Lot Lines" { PageType = ListPart; SourceTable = "Incoming Lot Line Tables"; ApplicationArea = All; Editable = true; layout { area(Content) { repeater(Group) { field("Metal Code"; Rec."Metal Code") { ApplicationArea = All; Editable = true; } field("Weight Standard"; Rec."Weight Standard") { ApplicationArea = All; } field("Weight"; Rec."Weight") { ApplicationArea = All; } field("OZ T C"; Rec."OZ T C") { ApplicationArea = All; DecimalPlaces = 0 : 5; Editable = false; } // 可选:隐藏LotReference字段,避免手动修改破坏关联 field("LotReference"; Rec."LotReference") { ApplicationArea = All; Editable = false; Visible = false; } } } } trigger OnOpenPage() begin Rec.SetFilter("Metal Code", 'PLT'); end; // 新增OnNewRecord触发器,自动填充关联字段 trigger OnNewRecord(BelowxRec: Boolean) var IncomingLotParent: Record "Incoming Lot Table"; begin // 获取父页面的当前入库批次记录 if Page.GetParent().GetRecord(IncomingLotParent) then Rec."LotReference" := IncomingLotParent."LineReferenceNumber"; end; }
关键说明
- OnNewRecord触发器:用户新增行时自动触发,通过
Page.GetParent().GetRecord()获取父页面的当前记录,提取LineReferenceNumber赋值给LotReference,完成关联。 - SubPageLink验证:父页面已设置
SubPageLink = "LotReference" = FIELD("LineReferenceNumber"),该配置会自动过滤ListPart显示的行,仅展示当前入库批次对应的明细,无需修改。 - 字段控制:可选隐藏
LotReference字段,防止用户手动修改,确保关联关系的准确性。
内容的提问来源于stack exchange,提问作者Het Patel
相关产品推荐
相关产品推荐

