Skip to content

Implement PromptDialog

Step 4 of 6

Overview

In the Schedule Sessions Copilot, the PromptDialog page is enhanced with features that auto runs the generation process, allow user selection for event durations, and enable history tracking of session scheduling.

1. New PromptDialog Properties

Begin by opening the file "src\4-ScheduleSessionsCopilot\PromptDialog\CopScheduleSessions.Page.al" and add the following properties:

PromptMode = Generate; // Triggers the Generate action automatically upon page open
SourceTable = "GPT Cop. Schedule Session Hst.";
SourceTableTemporary = true;

2. Prompt Options

Add a new section within the layout to allow users to choose the conference duration using predefined options:

layout
{
    area(PromptOptions)
    {
        field(ConferenceDuration; Duration)
        {
            Caption = 'Duration';
            ApplicationArea = All;
            ToolTip = 'Select the duration of the conference.';
        }
    }
}

3. Set Defaults

Implement default values and update them based on user selection using the following code snippet

var
    Duration: Enum "GPT Conference Duration";

procedure SetDefaultValues()
begin
    Duration := "GPT Conference Duration"::"2 Days"; // Sets the default duration to 2 Days.
end;

trigger OnAfterGetCurrRecord()
begin
    if Rec.IsEmpty() then
        exit;

    Duration := Rec."Conference Duration";
    GenerationIdText := 'Schedule sessions for : ' + Format(Duration) +
                        ' from 9:00 to 17:00 with 1 hour lunch break at 13:00'; // Update the header text based on the selected duration.
end;

4. Track History

Save History

To enable history tracking and manage generation iterations, add the following procedures:

local procedure SaveGenerationHistory()
begin
    if not Rec.IsEmpty then
        Rec.FindLast();

    Rec."Generation Id" := Rec."Generation Id" + 1;
    Rec."Conference Duration" := Duration;
    Rec.Insert;
end;

Initiate Generation

  • Add system actions Generate and Regenerate and call the GenerateSessionsScheduleProposal() function to trigger the generation process.

  • Use SaveGenerationHistory to save the current generation details and GenerateSessionsScheduleProposal to trigger the generation process:

    local procedure GenerateSessionsScheduleProposal()
    var
        ScheduleSessionsCopilotImpl: Codeunit "GPT Schedule Sessions Impl.";
        SessionScheduleProposal: Record "GPT Cop. Schedule Session";
    begin
        SaveGenerationHistory();
        ScheduleSessionsCopilotImpl.Generate(ProjectCode, Duration, Rec."Generation Id", SessionScheduleProposal);
        CurrPage.ScheduleSessionsProposal.Page.Load(SessionScheduleProposal);
    end;
    

Note

The Generate action is triggered automatically upon page open due to the PromptMode property set to Generate.

Info

With the introduction of history tracking, it's necessary to pass the generation ID to the generate function. This step is crucial as it allows us to associate each session schedule generation with its corresponding generation ID.

5. Present Results

Add Page Part

Finally, configure the content area to display the scheduled sessions:

area(Content)
{
    part(ScheduleSessionsProposal; "GPT Cop. Schedule Sessions Sub")
    {
        ApplicationArea = All;
        ShowFilter = false;
        Editable = true;
        Enabled = true;
        SubPageLink = "Generation Id" = field("Generation Id");
    }
}

This setup filters and displays only the session schedules relevant to the currently selected generation, allowing users to navigate through different proposals efficiently.

Finalize

On the Schedule Sessions Proposal page, add the Load function to display the generated session schedules:

    procedure Load(var SessionProposal: Record "GPT Cop. Schedule Session")
    begin
        If SessionProposal.FindSet() then
            repeat
                Rec := SessionProposal;
                Rec.Insert(true);
            until SessionProposal.Next() = 0;
    end;

Note

The Load function has been modified in the current version. Instead of using Rec.Copy(FromRec, true), it is recommended to loop through each record in FromRec and insert it into Rec when working with temporary records and applying filters based on the Generation Id field. This approach ensures expected behavior and avoids any unexpected issues.

6. Make your Copilot discoverable

Add your copilot to the Job List page to make it easily accessible to users. Open the "src\4-ScheduleSessionsCopilot\PromptDialog\CopScheduleSessionsExt.PageExt.al" file and add the required code.

Tip

Don't forget to set the default values to the copilot UI, by calling SetDefaultValues(), which will set the default duration to 2 days.

Conclusion

The improvements to the PromptDialog page in the Schedule Sessions Copilot make scheduling sessions easier and faster. They also offer a strong system for monitoring and analyzing various scheduling attempts, which aids in better event planning.

Next Steps

Move on to the next step to try the advanced prompt engineering techniques that enhance the copilot's scheduling capabilities.