I am quite new to building extensions with AL for Business Central. I am trying to setup an extension for a school application. The tables I have built work, and they follow this data model:
School - Course - Lecture
| /
Teacher
Inside the Card
for School
, I am showing a list part for Course
. It correctly shows all courses of a given school. So far so good. But now, whenever I create a Course
from this view, I have to remember to set the SchoolId
manually, but I would like to do this automatically because we already know which School
we are in.
The Course
table looks like this:
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;
}
}
}
The Course
list part explicitly does not contain the SchoolId
, as we would expect this to be managed automatically:
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; }
}
}
}
}
The School
card invokes the Course list part
on the appropriate view:
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;
}
}
}
}
}
And of course, the School
table, where the No.
property is set as the primary key:
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;
}
}
}
Still, no luck.