在Business CentralAL中从列表部分创建项目时,自动设置父ID。

问题描述 投票:-1回答:1

我对使用AL for Business Central建立扩展是很陌生的。我正试图为一个学校应用程序设置一个扩展。我建立的表可以使用,它们遵循这个数据模型。

School - Course - Lecture
  |     /
Teacher

在表的内部 Card 对于 School,我显示的是一个列表部分 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;
                }
            }
        }
    }
}

当然还有 School 表,其中 No. 属性被设置为主键。

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;
        }
    }
}

还是不行

customization dynamics-business-central al
1个回答
1
投票

当你将 "课程 "页面添加到 "学校页面 "时,子页面链接将自动为你处理这部分关系;当你插入一条新记录时,它将自动用 "SchoolId "填充No.。

如:在销售订单页面就是这样工作的。

 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 "必须在 "父表 "中。在你的代码中,'SchoolID'必须是'course'的主键。

© www.soinside.com 2019 - 2024. All rights reserved.