How to disable notes?

Hi experts,

In my Business Central cloud app, I have made an extension where my new table has notes attached to it using a factbox like this on the page:

area(factboxes)
{
systempart(Notes; Notes)
{
ApplicationArea = Notes;
Visible = true;
}
}

It works fine, but I don't want the user to change the notes that are attached to a specific table number.

I cannot make a table extension for the table "Record Link" and I cannot see which pages, I must extend. The notes must not be altered and must not be deleted. But it must be possible to press it and read the full text in view-only-mode.

I hope you can help me.

Best Answer

  • MortenSteengaardMortenSteengaard Member Posts: 136
    Answer ✓
    The problem can be solved by making these event subscriptions:

    [EventSubscriber(ObjectType::Table, Database::"Record Link", 'OnBeforeModifyEvent', '', false, false)]
    local procedure OnBeforeModifyEvent(var Rec: Record "Record Link"; var xRec: Record "Record Link"; RunTrigger: Boolean)
    begin
    if Rec."Record ID".TableNo() = Database::"my table" then begin
    Message('Modify is not allowed...');
    Rec.Note := xRec.Note; // undo the change
    end;
    end;

    [EventSubscriber(ObjectType::Table, Database::"Record Link", 'OnBeforeInsertEvent', '', false, false)]
    local procedure OnBeforeInsertEvent(var Rec: Record "Record Link"; RunTrigger: Boolean)
    begin
    if Rec."Record ID".TableNo() = Database::"my table" then begin
    Message('New note/link is not allowed...');
    end;
    end;

    [EventSubscriber(ObjectType::Table, Database::"Record Link", 'OnBeforeDeleteEvent', '', false, false)]
    local procedure OnBeforeDeleteEvent(var Rec: Record "Record Link"; RunTrigger: Boolean)
    begin
    if Rec."Record ID".TableNo() = Database::"my table" then begin
    Message('Delete is not allowed...');
    Error('Delete is not allowed...'); // This error message is never shown, but it prevents the record from being deleted
    end;
    end;

Answers

  • MortenSteengaardMortenSteengaard Member Posts: 136
    Answer ✓
    The problem can be solved by making these event subscriptions:

    [EventSubscriber(ObjectType::Table, Database::"Record Link", 'OnBeforeModifyEvent', '', false, false)]
    local procedure OnBeforeModifyEvent(var Rec: Record "Record Link"; var xRec: Record "Record Link"; RunTrigger: Boolean)
    begin
    if Rec."Record ID".TableNo() = Database::"my table" then begin
    Message('Modify is not allowed...');
    Rec.Note := xRec.Note; // undo the change
    end;
    end;

    [EventSubscriber(ObjectType::Table, Database::"Record Link", 'OnBeforeInsertEvent', '', false, false)]
    local procedure OnBeforeInsertEvent(var Rec: Record "Record Link"; RunTrigger: Boolean)
    begin
    if Rec."Record ID".TableNo() = Database::"my table" then begin
    Message('New note/link is not allowed...');
    end;
    end;

    [EventSubscriber(ObjectType::Table, Database::"Record Link", 'OnBeforeDeleteEvent', '', false, false)]
    local procedure OnBeforeDeleteEvent(var Rec: Record "Record Link"; RunTrigger: Boolean)
    begin
    if Rec."Record ID".TableNo() = Database::"my table" then begin
    Message('Delete is not allowed...');
    Error('Delete is not allowed...'); // This error message is never shown, but it prevents the record from being deleted
    end;
    end;
Sign In or Register to comment.