Skip to content

Implement PromptDialog

Step 3 of 7

Overview

In this section, you will create PromptDialog page for the Event Assistant Copilot in Dynamics 365 Business Central. The PromptDialog page allows users to interact with the Copilot by typing or selecting pre-defined questions and receiving AI-generated answers.

In general this copilot experience is very similar to the very first Generate Ideas copilot experience. The main difference is that the PromptDialog page is now connected to the Event Assistant AI logic, which will generate answers, using the functions you will implement in the next steps.

Also we add some predefined questions to the PromptGuide area to make it easier for the user to ask questions.

PromptDialog Page Setup

1. Open the Page File

Start by navigating to the file "\src\5-EventAssistantCopilot\PromptDialog\EventAssistant.Page.al" in your development environment. This file contains the basic structure of the PromptDialog page.

2. Define the Page Properties

Ensure that the page is set with the appropriate properties:

Caption = 'Answer event-related queries with Copilot';
PageType = PromptDialog;
IsPreview = true;
Extensible = false;

3. Setup the Input Field

The input field is where the user will type or select pre-defined questions:

field(InputText; InputText)
{
    ShowCaption = false;
    MultiLine = true;
    ApplicationArea = All;
}

4. Configure the Response Field

This field will display the AI-generated answer:

field(ResponseText; ResponseText)
{
    MultiLine = true;
    ApplicationArea = All;
    ShowCaption = false;
    Editable = false;
}

5. Implement the Generate Action

Add a Generate action to trigger the response generation process when the user asks a question:

systemaction(Generate)
{
    Caption = 'Ask';
    trigger OnAction()
    begin
        GetAnswer();
    end;
}

6. Add Prompt Guide Actions

Create quick access actions that fill the input field with common questions, facilitating user interaction:

group(HowMany)
{
    action(HowManySessions)
    {
        Caption = 'How many sessions are planned for the conference?';
        trigger OnAction()
        begin
            InputText := 'How many sessions are planned for the conference?';
        end;
    }
    action(HowManySessionsInTrack)
    {
        Caption = 'How many sessions are planned in the track [number]?';
        trigger OnAction()
        begin
            InputText := 'How many sessions are planned in the track no. ';
        end;
    }
}
group(When)
{
    action(WhenIsSession)
    {
        Caption = 'When is the session [name]?';
        trigger OnAction()
        begin
            InputText := 'When is the session ';
        end;
    }
    action(WhenSpeaker)
    {
        Caption = 'When is [speaker] speaking?';
        trigger OnAction()
        begin
            InputText := 'When is ';
        end;
    }
}

7. Configure the Backend Logic

Link the page to backend logic for fetching answers:

procedure GetAnswer()
var
    EventAssistantImpl: Codeunit "GPT Event Assist. Impl.";
begin
    EventAssistantImpl.GetAnswer(InputText, ResponseText, ProjectCode);
end;

Next Steps

Great! You have now set up the PromptDialog page for the Event Assistant Copilot.

In the next step, you will implement the backend logic to generate AI answers based on user queries.