web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

AL Code Help

(3) ShareShare
ReportReport
Posted on by 240

Hello all, 

i want to restrict some users to reopen the Document once released 

Pls help me to fix the issue in this

tableextension 55010 "User SetupPage(For Job Crate)" extends "User Setup"
{

    fields
    {
        field(55010; "Allow ReOpen"; Boolean)
        {
            Caption = 'Allow ReOpen';
            DataClassification = CustomerContent;
        }
    }
}



pageextension 55011 "User Setup Job Cr" extends "User Setup"
{
    layout
    {
        addafter("Register Time")
        {
            field("Allow ReOpen"; Rec."Allow ReOpen")
            {
                ApplicationArea = All;
                Caption = 'Allow ReOpen';
            }
        }
    }
}

pageextension 55012 "Purchase Order" extends "Purchase Order"
{
    layout
    {
        // Add changes to page layout here
    }

    actions
    {
        modify(Reopen)
        {
            ApplicationArea = all;
            trigger OnAction()
            var
                UserSetup: Record "User Setup";
            begin
                if UserSetup.Get(UserId) then
                    if UserSetup."Allow ReOpen" then
                        exit;

                Rec.Modify(false)
                Confirm: Label 'You Dont have a permission to Reopen';
                // CurrPage.Editable(false);
            end;

        }

    }
}

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Try to modify like below

    pageextension 55012 "Purchase Order" extends "Purchase Order"
    {
        layout
        {
            // Add changes to page layout here
        }

        actions
        {
            modify(Reopen)
            {
                ApplicationArea = all;
                trigger OnAction()
                var
                    UserSetup: Record "User Setup";
                begin
                    UserSetup.Get(UserId);
                        if not UserSetup."Allow ReOpen" then
                            Error('');
                end;

            }

        }
    }
  • LearnBC Profile Picture
    240 on at

    THanks for the reply NIthin

    but is not working  error-error AL0162: 'OnAction' is not a valid trigger

    pageextension 55012 "Purchase Order" extends "Purchase Order"

    {

       layout

       {

           // Add changes to page layout here

       }

       actions

       {

           modify(Reopen)

           {

               ApplicationArea = all;

               trigger OnAction()

               var

                   UserSetup: Record "User Setup";

               begin

                   UserSetup.Get(UserId);

                   if not UserSetup."Allow ReOpen" then

                       Error('You Dont have Permission to Reopen');

               end;

           }

       }

    }

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Can you try this?

     [EventSubscriber(ObjectType::Page, Page::"Purchase Order", 'OnBeforeActionEvent', 'Reopen', true, true)]
        local procedure OnBeforeActionEventWithPO(var Rec: Record "Purchase Header")
        var
            UserSetup: Record "User Setup";
        begin
            UserSetup.Get(UserId);
            if not UserSetup."Allow ReOpen" then
                Error('You Dont have Permission to Reopen');
        end;
  • Suggested answer
    pankaj.k Profile Picture
    1,020 on at

    Hi,

    Write code in Codeunit as suggest Nitin Verma that will definitely work.

    7318.Capture2.PNG

  • LearnBC Profile Picture
    240 on at

    Now its partially working

    while selecting the user from user setup page then also Reopen is disabled both cases

    RE1.jpg

    Codeunit 55013 "Purchase Order"
    {
    [EventSubscriber(ObjectType::Page, Page::"Purchase Order", 'OnBeforeActionEvent', 'Reopen', true, true)]
    local procedure OnBeforeActionEventWithPO(var Rec: Record "Purchase Header")
    var
    UserSetup: Record "User Setup";
    begin
    UserSetup.Get(UserId);
    if not UserSetup."Allow ReOpen" then
    Error('You Don't have Permission to Reopen');
    end;

    }

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Make sure you only Codeunit code should be used, other codes please comment them.

  • LearnBC Profile Picture
    240 on at

    Yes its already comment

    now only user setup page table extension,page extension and this code unit is there.

    its working but not enabling if we select the user from user setup

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    share your every line of code here.

  • LearnBC Profile Picture
    240 on at
    tableextension 55010 "User SetupPage(For Job Crate)" extends "User Setup"
    {

        fields
        {
            field(55010; "Allow ReOpen"; Boolean)
            {
                Caption = 'Allow ReOpen';
                DataClassification = CustomerContent;
            }
        }
    }
    pageextension 55011 "User Setup Job Cr" extends "User Setup"
    {
        layout
        {
            addafter("Register Time")
            {
                field("Allow ReOpen"; Rec."Allow ReOpen")
                {
                    ApplicationArea = All;
                    Caption = 'Allow ReOpen';
                }
            }
        }
    }
    Codeunit 55013 "Purchase Order"
    {
    [EventSubscriber(ObjectType::Page, Page::"Purchase Order", 'OnBeforeActionEvent', 'Reopen', true, true)]
    local procedure OnBeforeActionEventWithPO(var Rec: Record "Purchase Header")
    var
    UserSetup: Record "User Setup";
    begin
    UserSetup.Get(UserId);
    if not UserSetup."Allow ReOpen" then
    Error('You Don't have Permission to Reopen');
    end;

    }
  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    All code is correct, user setup's field should not be editable false with this code. do one thing

    pageextension 55011 "User Setup Job Cr" extends "User Setup"

    {

       layout

       {

           addafter("Register Time")

           {

               field("Allow ReOpen"; Rec."Allow ReOpen")

               {

                   ApplicationArea = All;

                   Editable = true;

                   Caption = 'Allow ReOpen';

               }

           }

       }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 755 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 413 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 387 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans