0

我对使用 AL for Business Central 构建扩展非常陌生。我正在尝试为学校申请设置扩展。我建立的表工作,他们遵循这个数据模型:

School - Course - Lecture
  |     /
Teacher

Cardfor 中School,我展示了 for 的列表部分Course。它正确显示给定学校的所有课程。到现在为止还挺好。但是现在,每当我从这个视图创建一个Course时,我必须记住SchoolId手动设置,但我想自动执行此操作,因为我们已经知道School我们在哪个视图中。

Course表如下所示:

table 50110 Course
{
    DataClassification = ToBeClassified;
    DrillDownPageId = "Course List";
    LookupPageId = "Course List";


    fields
    {
        field(1; "No."; Code[20])
        ...
        field(5; "SchoolId"; Code[20])
        {
            DataClassification = ToBeClassified;
            TableRelation = School."No.";
        }
    }

    keys
    {
        key(PK; "No.")
        {
            Clustered = true;
        }
    }
}

Course列表部分明确不包含SchoolId,因为我们希望它会自动管理:

page 50118 "Course List Part"
{
    PageType = ListPart;
    UsageCategory = None;
    SourceTable = Course;
    CardPageId = "Course Card";
    // InsertAllowed = false;

    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field("No."; "No.") { ApplicationArea = All; }
                field(Name; Name) { ApplicationArea = All; }
                field(CourseOwnerId; CourseOwnerId) { ApplicationArea = All; }
                // field(SchoolId; SchoolId) { ApplicationArea = All; }
            }
        }
    }
}

School卡片在适当的Course list part视图上调用:

page 50117 "School Card"
{
    PageType = Card;
    UsageCategory = None;
    SourceTable = School;

    layout
    {
        area(Content)
        {
            group(General)
            {
                field("No."; "No.")
                {
                    ApplicationArea = All;

                }
                field(Name; Name)
                {
                    ApplicationArea = All;

                }
            }
            group("Extras 1")
            {
                part("Courses"; "Course List Part")
                {
                    ApplicationArea = All;
                    SubPageLink = SchoolId = field("No.");
                    UpdatePropagation = Both;
                }
            }
        }
    }
}

当然,还有SchoolNo.属性设置为主键的表:

table 50113 School
{
    DataClassification = ToBeClassified;
    DrillDownPageId = "School List";
    LookupPageId = "School List";

    fields
    {
        field(1; "No."; Code[20])
        {
            DataClassification = ToBeClassified;
        }
        ...
    }

    keys
    {
        key(PK; "No.")
        {
            Clustered = true;
        }
    }
}

尽管如此,还是没有运气。

4

1 回答 1

1

当您将“课程”页面添加到“学校页面”时,子页面链接将自动为您处理该部分关系;当您插入新记录时,它会自动用“SchoolId”填充编号。

例如,这就是它在销售订单页面上的工作方式。

 part(SalesLines; "Sales Order Subform")
            {
                ApplicationArea = Basic, Suite;
                Editable = DynamicEditable;
                Enabled = "Sell-to Customer No." <> '';
                SubPageLink = "Document No." = FIELD("No.");
                UpdatePropagation = Both;
            }

您还必须定义从“子”表到“父”表的表关系,例如

table 50121 child
{ 
    fields
    {
        field(1; ParentID; Integer)
        {          
            TableRelation = Parent.ID;

您要链接的字段必须是子表的主键,即“SchoolID”必须在代码中“课程”的主键中。

于 2020-05-13T16:49:06.130 回答