Keep Suggestions¶
Overview¶
When a user is satisfied with the AI-generated project plan displayed on the PromptDialog page and decides to keep it, the data must be transferred from a temporary state into permanent project cards and task lines in the system. This step is critical as it turns provisional ideas into actionable project plans within Business Central.
Save Suggestions¶
1. Capture User Acceptance¶
Modify the PromptDialog page to handle the "Keep it" action effectively.
- Location: In the file
"\src\2-PlanningCopilot\PromptDialog\CopilotProjectProposal.Page.al" - Action Setup: Ensure the
OKsystem action is set to trigger the saving process.
2. Define Close Logic¶
Check that you have implemented the logic to save the data when the page closes after the user clicks on "Keep it".
trigger OnQueryClosePage(CloseAction: Action): Boolean
begin
if CloseAction = CloseAction::OK then
ApplyProposedProjectPlan();
end;
3. Apply Project Plan¶
Create a procedure to handle the transition of data from temporary storage to permanent records.
- Procedure Logic:
local procedure ApplyProposedProjectPlan() var SaveProjectPlanCopilotImpl: Codeunit "GPT Save Project Plan Copilot"; CopilotJobProposal: Record "GPT Copilot Job Proposal"; begin CurrPage.ProposalDetails.Page.GetRecords(CopilotJobProposal); SaveProjectPlanCopilotImpl.ApplyProposedProjectPlan(CopilotJobProposal); end;
4. Copy Records¶
Ensure the page part associated with the PromptDialog correctly passes all records to be saved.
- Location: Modify
"\src\2-PlanningCopilot\PromptDialog\CopilotJobProposalSubpart.Page.al" - GetRecords Procedure:
5. Implement Save Logic¶
Create detailed logic in the \src\2-PlanningCopilot\Implementation\SaveProjectPlanCopilot.Codeunit.al codeunit to establish new project cards and task lines from the passed records.
- Codeunit Implementation: Handle the creation of project and task records based on the structured data received from the AI. This includes setting up tasks, assigning resources or items as needed, and ensuring all dates and descriptions are correctly aligned with the AI's proposals.
Implement ApplyProposedProjectPlan procedure
if CopilotJobProposal.FindSet() then begin
Job := CreateJob(CopilotJobProposal."Job Short Description");
repeat
JobTask := CreateJobTask(Job."No.", CopilotJobProposal);
if JobTask."Job Task Type" = JobTask."Job Task Type"::Posting then
CreateJobPlanningLine(JobTask, CopilotJobProposal);
until CopilotJobProposal.Next() = 0;
end;
6. Create Project and Tasks¶
Ensure that the CreateJob, CreateJobTask, and CreateJobPlanningLine procedures are correctly implemented to create new project cards and task lines in Business Central.
- CreateJob: Create a new project card based on the AI-generated job description.
local procedure CreateJob(JobDescription: Text[100]) Job: Record Job
var
begin
Job.Init();
Job.Description := JobDescription;
Job.Validate("Bill-to Customer No.", FindFirstCustomer());
Job.Validate("Starting Date", FindFirstAvailableDateInAllowedLicensePeriod());
Job.Insert(true);
end;
local procedure FindFirstCustomer(): Code[20]
var
Customer: Record Customer;
begin
if not Customer.FindFirst() then
exit;
exit(Customer."No.");
end;
local procedure FindFirstAvailableDateInAllowedLicensePeriod(): Date
begin
exit(DMY2Date(1, 12, Date2DMY(Today(), 3)));
end;
Note
The FindFirstCustomer procedure is a placeholder for a more sophisticated customer selection process based on the project requirements. You can change the AI logic to put customer, mentioned in the user input, for example.
- CreateJobTask: Create a new task line within the project card based on the AI-generated task details.
local procedure CreateJobTask(JobNo: Code[20]; var CopilotJobProposal: Record "GPT Copilot Job Proposal" temporary) JobTask: Record "Job Task"
begin
JobTask.Init();
JobTask.Validate("Job No.", JobNo);
JobTask.Validate("Job Task No.", CopilotJobProposal."Job Task No.");
JobTask.Validate(Description, CopilotJobProposal."Task Description");
JobTask.Validate("Job Task Type", CopilotJobProposal."Job Task Type");
JobTask.Validate(Indentation, CopilotJobProposal.Indentation);
JobTask.Insert(true);
end;
Testing and Validation¶
Once implemented, test this functionality to ensure that: - Data is accurately captured from the AI-generated proposals. - Projects and tasks are correctly saved in Business Central. - All user edits prior to saving are preserved and reflected in the final records.
Conclusion¶
By completing this task, you have successfully integrated the "Keep Suggestions" feature into your Project Planning Copilot, allowing users to save AI-generated project proposals as actual records in Dynamics 365 Business Central.
Congratulations!¶
Now you've implemented the Project Planning Copilot - AI-powered assistant that helps you create a project card and set tasks, assignees, and due dates for each task, based on project description.