Übung – Mit „Unterstützte Einrichtung“ eine Assistentenseite erstellen

Abgeschlossen

Szenario

Sie sind ein Entwickler und arbeiten für CRONUS International Ltd. Sie wurden aufgefordert, eine unterstützte Einrichtung erstellen, um Einträge einer Aufgabenliste hinzuzufügen. Mit der unterstützten Einrichtung können Benutzer einer Aufgabenliste Einträge hinzufügen, die in der Tabelle „Aufgaben“ gespeichert wird. Der Code für den ersten Schritt sollte einen Teil enthalten, der die Seite „Attendee Wizard Subform“ der Basisanwendung erneut verwendet. In diesem Teil können Benutzer beim ersten Start der Einrichtung den Verkäufer auswählen, dem die Aufgabe zugeordnet ist.

Aufgaben

  • Erstellen Sie eine Assistentenseite.

  • Erstellen Sie eine Codeunit.

  • Erstellen Sie eine Enumerationserweiterung.

Schritte

Eine Assistentenseite erstellen

  1. Erstellen Sie eine neue Seite mit dem Namen ToDoAssistedSetup.Page.al.

  2. Fügen Sie der Datei den folgenden Code hinzu:

    page 50111 ToDoAssistedSetup
    {
        PageType = NavigatePage;
        SourceTable = "To-do";
        SourceTableTemporary = true;
        Caption = 'Add a To-do for the Team';
    
        layout
        {
            area(content)
            {
                group(Step1)
             {
                 Visible = Step1Visible;
    
                 group("Welcome")
                 {
                     Caption = 'Welcome to the to-do assisted setup';
                     group(group11)
                     {
                         Caption = '';
                         InstructionalText = 'Use this guide to register a to-do task for you and your team.';
                     }
                 }
                 group("Let's go")
                 {
                     Caption = 'Let's go';
                     group(group12)
                     {
                         Caption = '';
                         InstructionalText = 'Select Next to get started.';
                     }
                 }
             }
             group(Step2)
             {
                 Caption = 'Enter information about the to-do task';
                 Visible = Step2Visible;
    
                 group("11")
                 {
                     Caption = 'Add attendees and fill in details';
                     part(AttendeeSubForm; "Attendee Wizard Subform")
                     {
                     }
                 }
                 field("No."; Rec."No.")
                 {
                     ApplicationArea = All;
                     Visible = false;
                     ToolTip = 'The number of the to-do.';
                 }
                 field("Type"; Rec."Type")
                 {
                     ApplicationArea = All;
                     Caption = 'What type is the to-do?';
                     ToolTip = 'The type of the to-do.';
                 }
                 field("Date"; Rec."Date")
                 {
                     ApplicationArea = All;
                     Caption = 'What''s the start date?';
                     ToolTip = 'The start date of the to-do.';
                 }
                 field("Description"; Rec.Description)
                 {
                     ApplicationArea = All;
                     Caption = 'Describe your to-do';
                     ToolTip = 'The description of the to-do.';
                 }
                 field("Start Time"; Rec."Start Time")
                 {
                     ApplicationArea = All;
                     Caption = 'What''s the start time?';
                     ToolTip = 'The start time of the to-do.';
                 }
                 field("Duration"; Rec."Duration")
                 {
                     ApplicationArea = All;
                     Caption = 'How long does it last?';
                     ToolTip = 'The duration of the to-do.';
                 }
                 field("Team To-do"; Rec."Team to-do")
                 {
                     ApplicationArea = All;
                     Caption = 'Team to-do';
                     ToolTip = 'The team to-do.';
                 }
                 field("All Day Event"; Rec."All Day Event")
                 {
                     ApplicationArea = All;
                     Caption = 'All Day Event';
                     ToolTip = 'The all day event.';
                 }
                 field("Ending Date"; Rec."Ending Date")
                 {
                     ApplicationArea = All;
                     Caption = 'What''s the end date?';
                     ToolTip = 'The end date of the to-do.';
                 }
                 field("Ending Time"; Rec."Ending Time")
                 {
                     ApplicationArea = All;
                     Caption = 'What''s the end time?';
                     ToolTip = 'The end time of the to-do.';
                 }
             }
             group(Step3)
             {
                 Caption = 'That''s it!';
                 InstructionalText = 'Select Finish to save the to-do.';
                 Visible = Step3Visible;
    
             }
             group(StandardBanner)
             {
                 Caption = '';
                 Editable = false;
                 Visible = TopBannerVisible and not FinishActionEnabled;
                 field(MediaResourcesStandard; MediaResourcesStandard."Media Reference")
                 {
                     ApplicationArea = All;
                     Editable = false;
                     ShowCaption = false;
                 }
             }
             group(FinishedBanner)
             {
                 Caption = '';
                 Editable = false;
                 Visible = TopBannerVisible and FinishActionEnabled;
                 field(MediaResourcesDone; MediaResourcesDone."Media Reference")
                 {
                     ApplicationArea = All;
                     Editable = false;
                     ShowCaption = false;
                 }
             }
         }
     }
    
     actions
     {
         area(Processing)
         {
             action(Back)
             {
                 ApplicationArea = All;
                 Caption = '&Back';
                 Enabled = BackEnable;
                 InFooterBar = true;
                 Image = PreviousRecord;
    
                 trigger OnAction()
                 begin
                     NextStep(true);
                 end;
             }
             action(Next)
             {
                 ApplicationArea = All;
                 Caption = '&Next';
                 Enabled = NextEnable;
                 InFooterBar = true;
                 Image = NextRecord;
    
                 trigger OnAction()
                 begin
                     NextStep(false);
                 end;
             }
             action(Finish)
             {
                 ApplicationArea = All;
                 Caption = '&Finish';
                 Enabled = FinishEnable;
                 InFooterBar = true;
                 Image = Approve;
    
                 trigger OnAction()
                 begin
                     Finished();
                 end;
             }
         }
     }
    
    
     trigger OnInit()
     var
    
     begin
    
         EnableControls();
         LoadTopBanners();
     end;
    
     trigger OnOpenPage()
     begin
         ToDoRec.Get();
         ToDoRec.Init;
         Rec := ToDoRec;
         CurrPage.Update();
     end;
    
     var
         BackEnable: Boolean;
         NextEnable: Boolean;
         FinishEnable: Boolean;
         Step1Visible: Boolean;
         Step2Visible: Boolean;
         Step3Visible: Boolean;
         Step: Option Start,Fill,Finish;
         ToDoRec: Record "To-do";
         TopBannerVisible: Boolean;
         FinishActionEnabled: Boolean;
         MediaRepositoryDone: Record "Media Repository";
         MediaRepositoryStandard: Record "Media Repository";
         MediaResourcesDone: Record "Media Resources";
         MediaResourcesStandard: Record "Media Resources";
    
     local procedure NextStep(Backwards: Boolean)
     begin
         if Backwards then
             Step := Step - 1
         else
             Step := Step + 1;
    
         EnableControls();
     end;
    
     local procedure Finished()
     begin
         StoreRecordVar();
         CurrPage.Close();
     end;
    
     local procedure EnableControls()
     begin
         ResetControls();
         case Step of
             Step::Start:
                 ShowStep1();
             Step::Fill:
                 ShowStep2();
             Step::Finish:
                 ShowStep3();
         end;
     end;
    
     local procedure ShowStep1()
     begin
         Step1Visible := true;
         BackEnable := false;
         NextEnable := true;
         FinishEnable := false;
     end;
    
     local procedure ShowStep2()
     begin
         Step2Visible := true;
         BackEnable := true;
         NextEnable := true;
         FinishEnable := false;
     end;
    
     local procedure ShowStep3()
     begin
         Step3Visible := true;
         BackEnable := true;
         NextEnable := false;
         FinishEnable := true;
         FinishActionEnabled := true
     end;
    
     local procedure ResetControls();
     begin
         FinishEnable := false;
         BackEnable := true;
         NextEnable := true;
         Step1Visible := false;
         Step2Visible := false;
         Step3Visible := false;
    
     end;
    
     local procedure StoreRecordVar();
     begin
         ToDoRec.TransferFields(Rec, true);
         ToDoRec.Insert();
     end;
    
     local procedure LoadTopBanners();
     begin
         if MediaRepositoryStandard.Get('AssistedSetup-NoText-400px.png', Format(CurrentClientType())) and
             MediaRepositoryDone.Get('AssistedSetupDone-NoText-400px.png', Format(CurrentClientType()))
         then
             if MediaResourcesStandard.Get(MediaRepositoryStandard."Media Resources Ref") and
                 MediaResourcesDone.Get(MediaRepositoryDone."Media Resources Ref")
         then
                 TopBannerVisible := MediaResourcesDone."Media Reference".HasValue();
    
     end;
    }
    
  3. Beachten Sie, dass die Eigenschaf tSourceTable auf Aufgabe gesetzt wurde und die Eigenschaft Caption auf Eine Aufgabe für das Team hinzufügen.

  4. Die Eigenschaft PageType ist NavigatePage.

  5. Es gibt im Inhaltsbereich drei verschiedene Gruppen. Jede Gruppe repräsentiert einen Schritt, Schritt 1, Schritt 2 und Schritt 3.

  6. Im Bereich Verarbeitung gibt es Navigationsaktionen: Zurück, Weiter und Fertig.

  7. Die Eigenschaft InFooterBar ist für die drei Aktionen auf true gesetzt.

  8. Es gibt drei globale boolesche Variablen:

    • BackActionEnabled

    • NextActionEnabled

    • FinishActionEnabled

  9. Die Eigenschaft Enabled ist für jede Aktion für die entsprechende globale boolesche Variable eingerichtet.

  10. Die Eigenschaft Image für jede Aktion ist ebenfalls eingerichtet. Verwenden Sie für die Aktion Zurück PreviousRecord, für die Aktion Weiter NextRecord und für die Aktion Fertig stellen Approve.

  11. Beachten Sie, dass es einige Verfahren gibt, um die Aktionen zu vereinfachen und die Bannersymbole zu laden.

Eine Codeunit erstellen

  1. Wählen Sie Datei > Neue Datei aus, und speichern Sie diese Datei anschließend durch Auswahl von Datei > Speichern. Verwenden Sie den Dateinamen AddToDoAssistedSetup.CodeUnit.al.

  2. Erstellen Sie eine neue Codeunit in dieser Datei, indem Sie Codeausschnitte verwenden. Geben Sie tcodeunit ein, und drücken Sie dann die TAB-TASTE.

  3. Fügen Sie den folgenden Code hinzu:

       codeunit 50103 AddToDoAssistedSetup
       {
           [EventSubscriber(ObjectType::Codeunit, Codeunit::"Guided Experience", 'OnRegisterAssistedSetup', '', true, true)]
           local procedure OnRegisterAssistedSetup()
           var
               AssistedSetup: Codeunit "Guided Experience";
               GuidedExperienceType: Enum "Guided Experience Type";
               AssistedSetupGroup: Enum "Assisted Setup Group";
               VideoCategory: Enum "Video Category";
           begin
               if not AssistedSetup.Exists(GuidedExperienceType::"Assisted Setup",
                     ObjectType::Page,
                     Page::"ToDoAssistedSetup") then
                 AssistedSetup.InsertAssistedSetup(
                         'Add a to-do',
                         'Create a task for your team',
                         'Register a task for your team and assign people',
                         1,
                         ObjectType::Page,
                         Page::ToDoAssistedSetup,
                         AssistedSetupGroup::Tasks,
                         '',
                         VideoCategory::Uncategorized,
                         '');
           end;
       }
    
  4. Fügen Sie ein Enumerationserweiterungs-Objekt mit dem Namen AssistedSetupGroup.EnumExt.al hinzu

  5. Fügen Sie den folgenden Code hinzu:

    enumextension 50100 AssistedSetupGroup extends "Assisted Setup Group"
    {
        value(100; Tasks)
        {
        }
    }
    
  6. Veröffentlichen Sie Ihre Erweiterung in der Sandbox. Wählen Sie Anzeigen > Befehlspalette ... (STRG+UMSCHALT+P) aus.

  7. Geben Sie AL: Publish in das Suchfeld ein (oder drücken Sie die F5-Taste), und wählen Sie dann den Befehl aus der Liste aus.

  8. Sie können die Unterstützte Einrichtung durch die Suche nach Unterstützte Einrichtung im Suchfeld testen.