PromptDialog Page¶
To implement the Import Any Excel Copilot effectively, we'll focus on integrating file upload capabilities and automating the field mapping process without requiring user-generated text input. This approach, called as structured input, emphasizes the use of AI to facilitate data import tasks. Below is a detailed explanation and guide on setting up the PromptDialog page for this copilot:
PromptDialog Setup¶
1. Define Page Properties¶
Start by setting up the basic properties of the PromptDialog page in AL:
- PageType: PromptDialog
- Caption: 'Import from any excel with Copilot'
- IsPreview: true, indicating that the feature is in a preview or testing phase.
- PromptMode: Prompt, even though the user will not be directly prompted for text input, this mode is used to guide the user through the import process.
2. Layout Implementation¶
Organize the layout into two main areas, the Prompt and Content areas, to facilitate user interaction and data display.
Prompt Area¶
- Project Group: Display the project number and description, which are pre-initialized and not editable by the user. This informs the user which project the sessions will be imported into. Global Project variable is initiated in the
SetProject, called from the parentJob Listpage.
- Excel File Group: Include a field to show the name of the uploaded file, enhancing user feedback by confirming that the file has been successfully uploaded. This field will be updated dynamically when a file is attached. Use the
FileNamevariable to display the file name.
Content Area¶
- Field Mapping Proposal Part: Integrate a sub-part page where the proposed field mappings will be displayed. This part allows the user to review and confirm the mappings suggested by the AI before finalizing the import. Use the
"GPT Cop. Imp. Excel Subpart"to display the mappings.
3. Define Actions¶
Set up the actions necessary for file management and data processing:
- Attach Action: Implement an action that allows users to upload the Excel file. This action should also handle the file reading and display the file name once uploaded.
- Generate Action: This triggers the AI to analyze the uploaded file and generate field mappings based on the Excel column headers and Business Central field definitions.
systemaction(Generate)
{
Caption = 'Map Fields';
trigger OnAction()
begin
GenerateFieldMappingProposal();
end;
}
- Regenerate Action: Allows users to re-generate mappings if necessary, providing flexibility in handling the imported data. This action is useful when the initial mappings are incorrect or need adjustment.
Regenerate action is similar to the Generate action, as both actions call the same function GenerateFieldMappingProposal. This design ensures that users can re-attempt the mapping process without having to re-upload the file.
4. User Acceptance Logic¶
Add system action of type OK and Caption Import to handle the final import process. This action will be triggered when the user confirms the field mappings and is ready to import the data into Business Central.
Implement logic in the OnQueryClosePage trigger to handle the final import process when the user confirms the mappings:
- Apply Import of Sessions: When the user clicks "Keep it," this function will be triggered to save the mapped data into the Business Central sessions table based on the confirmed mappings.
trigger OnQueryClosePage(CloseAction: Action): Boolean
begin
if CloseAction = CloseAction::OK then
AppyImportOfSessions();
end;
Code Snippets
Here are the key parts of code that developers will need to implement or modify:
group(Project)
{
field(ProjectNo; Project."No.")
{
ApplicationArea = All;
Caption = 'Project No.';
Editable = false;
}
field(ProjectDescription; Project.Description)
{
ApplicationArea = All;
Caption = 'Project Description';
Editable = false;
MultiLine = true;
}
}
field(FileName; FileName)
{
ApplicationArea = All;
Caption = 'Excel File';
Editable = false;
}
part(FieldMappingProposal; "GPT Cop. Imp. Excel Subpart")
{
ApplicationArea = All;
ShowFilter = false;
Editable = true;
Enabled = true;
}
5. Discoverability¶
Now add the "GPT Cop. Imp. Excel" page to the "Job List" page, so that users can easily access it. Comparing to the previous task, you should do it differently, as we need to pre initialize the project number and description in the SetProject function.
trigger OnAction()
var
CopilotImportFromExcel: Page "GPT Cop. Imp. Excel";
begin
CopilotImportFromExcel.SetProject(Rec);
CopilotImportFromExcel.RunModal();
end;
Conclusion¶
By following these steps, you will set up a PromptDialog page that effectively handles Excel file uploads (implement in the Attach Files step) and automates the field mapping process (implement in the AI Logic step), making the data import process seamless and user-friendly. The main advantage of this approach is that it reduces the need for custom import solutions for different Excel formats, making this the only one-size-fits-all solution for importing data into Business Central.
Next Steps¶
Move on to the next step to implement the file upload functionality and the AI logic for generating field mappings based on the uploaded Excel file.