Graphical Scheduler Development Example – Prompting for a reason code

Skip to main content

Graphical Scheduler Development Example – Prompting for a reason code

You are here:

The Graphical Scheduler provides multiple integration events (hooks) that allow developers to alter existing scheduling behaviors or implement entirely new logic within Microsoft Dynamics 365 Business Central. This technical article walks through three advanced extension examples using the Graphical Scheduler development framework.

Technical Skills and Tools Required

To implement these customizations, ensure you have the following setup:

  • Environment: Microsoft Dynamics 365 Business Central (e.g., inside a Docker container on a Virtual Machine).

  • Development Tools: Visual Studio Code (VS Code) with the AL Language extension.

  • Core Understanding: A foundational grasp of Business Central concepts (such as manufacturing data routing, data types, and standard tables).

Intercepting Drag-and-Drop and Prompting for Reason Codes

This example works through how to develop an extension such that when a user manipulates scheduled cells via drag-and-drop, to implement a compliance audit trail. This example demonstrates how to intercept a schedule modification before it writes to the database, prompt the user for a reason code, and log a history record.

Full example code can be found here: https://dev.azure.com/InsightWorks/External%20Examples/_git/Techworks2024?path=/D08%20-%20Graphical%20Scheduler/Example1-PromptForReasonCode

1. Create the Audit Log Architecture

First, define a custom table and a matching card page to store your captured audit record details:

Code snippet

table 50100 "GS Change Audit Log"
{
    DataClassification = CustomerContent;

    fields
    {
        field(1; "Entry No."; Integer) { AutoIncrement = true; }
        field(2; "Changed Record ID"; RecordId) { }
        field(3; "User ID"; Code[50]) { }
        field(4; "Changed DateTime"; DateTime) { }
        field(5; "Reason Code"; Code[10]) { TableRelation = "Reason Code"; }
        field(6; "Comment"; Text[250]) { }
    }
    keys { key(PK; "Entry No.") { Clustered = true; } }
}

2. Hook Into the Schedule Modification Event

Subscribe to the OnBeforeScheduleChangeBeforeDataCodeunit integration event provided by the Graphical Scheduler extension. This event gives you access to a copy of the target JSON object and the corresponding cell buffer record before database execution:

codeunit 50101 "GS Audit Log Management"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"IWX Scheduler Event Publisher", 'OnBeforeScheduleChangeBeforeDataCodeunit', '', false, false)]
    local procedure LogScheduleChangePrompt(var pvarCellBuffer: Record "IWX Scheduler Cell Buffer"; var pjsonCell: JsonObject; var pblnHandled: Boolean)
    var
        AuditLog: Record "GS Change Audit Log";
        AuditCard: Page "GS Change Audit Card";
    begin
        AuditLog.Init();
        AuditLog."Changed Record ID" := pvarCellBuffer."Record ID";
        AuditLog."User ID" := UserId;
        AuditLog."Changed DateTime" := CurrentDateTime;
        AuditLog.Insert(true);

        Commit(); // Commit transaction before running an interactive modal page

        Clear(AuditCard);
        AuditCard.SetRecord(AuditLog);
        AuditCard.LookupMode(true);
        
        if AuditCard.RunModal() = Action::LookupCancel then begin
            AuditLog.Delete();
            pblnHandled := true; // Cancels the graphical drop operation completely
        end;
    end;
}
Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Need help?

Leave A Comment

Table of Contents
Go to Top