Ejercicio: Usar instrucciones de manipulación de datos
Trabaja como desarrollador para CRONUS International Ltd. Ha aprendido a usar las instrucciones de manipulación de datos en AL y ahora quiere practicar con esta nueva capacidad en el entorno de desarrollo. Quiere poder exportar registros de contabilidad a una tabla específica. El cliente debe llevar a cabo esta tarea y código de origen para que usted tenga una visión general de los importes totales por cliente y código de origen.
Tareas
Crear una nueva extensión AL.
Crear una nueva tabla.
Crear una página que esté vinculada a la tabla.
Crear una codeunit para copiar datos de diferentes tablas a la tabla recién creada.
Pasos
En Visual Studio Code, en el proyecto que ha creado antes en esta ruta de aprendizaje, cree una nueva carpeta llamada CustomerOverview.
Cree todos los nuevos archivos .al mencionados en los siguientes pasos, en la carpeta CustomerOverview.
Seleccione Archivo > Nuevo archivo y guarde este archivo seleccionando Archivo > Guardar. Ponga al archivo el nombre CustomerOverview.Table.al.
Cree una nueva tabla en este archivo mediante el uso de fragmentos de código. Introduzca
ttabley pulse la tecla Tab.Cambie el Id. a 50120 y el nombre a "Customer Overview".
Establezca la propiedad DataClassification en CustomerContent y la propiedad Caption en Customer Overview.
Quite el campo MyField.
Cree los siguientes campos. Puede usar el fragmento
tfield.N.° de campo Nombre de campo Tipo de datos Longitud 1 Entry No. Integer 2 Customer No. Code 20 3 Customer Name Text 100 4 Source Code Code 20 5 Amount Decimal 6 LastRunDate DateTime Establezca la propiedad DataClassification de cada campo de la tabla en CustomerContent.
Establezca la propiedad Caption de cada campo de la tabla.
Establezca el campo Clave principal en Entry No.
Elimine la sección de variables globales.
Elimine los desencadenadores de tabla.
El archivo debería parecerse a este bloque de código:
table 50120 "Customer Overview" { DataClassification = CustomerContent; Caption = 'Customer Overview'; fields { field(1; "Entry No."; Integer) { DataClassification = CustomerContent; Caption = 'Entry No.'; } field(2; "Customer No."; code[20]) { DataClassification = CustomerContent; Caption = 'Customer No.'; } field(3; "Customer Name"; Text[100]) { DataClassification = CustomerContent; Caption = 'Customer Name'; } field(4; "Source Code"; Code[20]) { DataClassification = CustomerContent; Caption = 'Source Code'; } field(5; "Amount"; Decimal) { DataClassification = CustomerContent; Caption = 'Amount'; } field(6; "LastRunDate"; DateTime) { DataClassification = CustomerContent; Caption = 'LastRunDate'; } } keys { key(Pk; "Entry No.") { Clustered = true; } } }Cree un nuevo archivo con el nombre CustomerOverviewList.Page.al.
Cree una nueva página en este archivo mediante el uso de fragmentos de código. Introduzca
tpagey pulse la tecla Tab.Cambie el Id. a 50120 y el nombre a Customer Overview List.
Establezca la propiedad SourceTable en Customer Overview y la propiedad Caption en Customer Overview List.
Establezca la propiedad PageType en List y la propiedad UsageCategory en Lists. Compruebe que la propiedad ApplicationArea esté establecida en All.
Establezca la propiedad Editable en false.
Compruebe que se haya creado un área content en la sección de diseño. De no ser así, cree un área denominada content.
Cambie el nombre del repetidor a General.
Agregue todos los campos de la tabla Customer Overview que creó anteriormente, dentro del repetidor.
Compruebe que la propiedad ApplicationArea esté establecida en All para todos los campos de la página.
Agregue información sobre herramientas significativa en todos los campos de la página.
Elimine el área factboxes.
Elimine el área actions.
El archivo debería parecerse a este bloque de código:
page 50120 "Customer Overview List" { PageType = List; ApplicationArea = All; UsageCategory = Lists; SourceTable = "Customer Overview"; Caption = 'Customer Overview List'; Editable = false; layout { area(Content) { repeater(General) { field("Entry No."; Rec."Entry No.") { ToolTip = 'Specifies the value of the Entry No. field.'; ApplicationArea = All; } field("Customer No."; Rec."Customer No.") { ToolTip = 'Specifies the value of the Customer No. field.'; ApplicationArea = All; } field("Customer Name"; Rec."Customer Name") { ToolTip = 'Specifies the value of the Customer Name field.'; ApplicationArea = All; } field("Source Code"; Rec."Source Code") { ToolTip = 'Specifies the value of the Source Code field.'; ApplicationArea = All; } field(Amount; Rec.Amount) { ToolTip = 'Specifies the value of the Amount field.'; ApplicationArea = All; } field(LastRunDate; Rec.LastRunDate) { ToolTip = 'Specifies the value of the LastRunDate field.'; ApplicationArea = All; } } } } }Cree un nuevo archivo con el nombre CustomerOverviewMgmt.CodeUnit.al.
Cree una nueva codeunit en este archivo mediante el uso de fragmentos de código. Introduzca
tcodeunity pulse la tecla Tab.Cambie el Id. a 50120 y el nombre a Customer Overview Mgmt.
Agregue las siguientes variables globales.
Nombre Tipo de datos Subtipo CustomerOverview Registro Vista general de cliente Cliente Registro Cliente SourceCode Registro Source Code GLEntry Registro Movimiento de contabilidad NextEntryNo Integer En el desencadenador
OnRun, agregue el siguiente código.Clear(SourceCode); Clear(CustomerOverview); Clear(GLEntry); if CustomerOverview.FindLast() then NextEntryNo := CustomerOverview."Entry No." + 1 else NextEntryNo := 1; if SourceCode.FindSet() then repeat if Customer.FindSet() then repeat GLEntry.SetRange("Source Type", GLEntry."Source Type"::Customer); GLEntry.SetRange("Source Code", SourceCode.Code); GLEntry.SetRange("Source No.", Customer."No."); if GLEntry.FindSet() then begin GLEntry.CalcSums(GLEntry.Amount); CustomerOverview."Entry No." := NextEntryNo; CustomerOverview."Customer No." := Customer."No."; CustomerOverview."Customer Name" := Customer.Name; CustomerOverview."Source Code" := SourceCode.Code; CustomerOverview.Amount := GLEntry.Amount; CustomerOverview.LastRunDate := CurrentDateTime(); CustomerOverview.Insert(); NextEntryNo += 1; end; until Customer.Next() = 0; until SourceCode.Next() = 0Abra el archivo CustomerOverviewList.Page.al.
Agregue un área actions en la página.
En el área actions, agregue una sección Processing.
En la sección Processing, agregue una acción.
Cambie el nombre de la acción a Import Records y establezca las siguientes propiedades en esa acción:
Caption: Import Records
Image: Import
ApplicationArea: All
En el desencadenador
OnAction, cree una variable local.Nombre Tipo de datos Subtipo UpdateCustomerOverview Codeunit Customer Overview Mgmt Llame a la codeunit
RunTriggerdesde el desencadenadorOnAction.El código debería parecerse a este bloque de código:
page 50120 "Customer Overview List" { PageType = List; ApplicationArea = All; UsageCategory = Lists; SourceTable = "Customer Overview"; Caption = 'Customer Overview List'; Editable = false; layout { area(Content) { repeater(General) { field("Entry No."; Rec."Entry No.") { ToolTip = 'Specifies the value of the Entry No. field.'; ApplicationArea = All; } field("Customer No."; Rec."Customer No.") { ToolTip = 'Specifies the value of the Customer No. field.'; ApplicationArea = All; } field("Customer Name"; Rec."Customer Name") { ToolTip = 'Specifies the value of the Customer Name field.'; ApplicationArea = All; } field("Source Code"; Rec."Source Code") { ToolTip = 'Specifies the value of the Source Code field.'; ApplicationArea = All; } field(Amount; Rec.Amount) { ToolTip = 'Specifies the value of the Amount field.'; ApplicationArea = All; } field(LastRunDate; Rec.LastRunDate) { ToolTip = 'Specifies the value of the LastRunDate field.'; ApplicationArea = All; } } } } actions { area(Processing) { action("Import Records ") { Caption = 'Import Records'; ToolTip = 'Import Records'; ApplicationArea = All; Image = Import; trigger OnAction() var CustomerOverviewMgmt: Codeunit "Customer Overview Mgmt"; begin CustomerOverviewMgmt.Run(); end; } } } }Abra el archivo launch.json, en la carpeta .vscode. Establezca la configuración startupObjectId en 50120 y la configuración startupObjectType en Page.
Publique su extensión en el espacio aislado. Seleccione Ver > Paleta de comandos (Ctrl+Mayús+P).
Introduzca AL: Publish en el cuadro de búsqueda (o presione la tecla F5) y, a continuación, seleccione el comando de la lista.
Compruebe que se inicia la aplicación Microsoft Dynamics 365 Business Central y que aparece la página Customer Overview List.
Pruebe la extensión seleccionando la acción Importar registros.