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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

Disable Menu with the AL Code

(0) ShareShare
ReportReport
Posted on by 240

Dear All,

i have one issue in this new requirement

We want to allow/restrict the users to reopen the Purchase order once its released. only allowed user can should have to do this

for this i have created like this Pls correct me where i did the makes the Mistakes

I created a table extension in User setup with Boolean value and Codeunit for this.  is this is the right way.

tableextension 60100 "User Setup Ext" extends "User Setup"
{
    fields
    {
        // Add changes to table fields here
        field(60102; "Purchase Order Release"; Boolean)
        {
            Caption = 'PO Release';
            Data Classification = Customer Content;
        }
    }


}
codeunit 60105 PreventRelease
{

    trigger onRun()
    begin

    end;

    [EventSubscriber(ObjectType::CodeunitCodeunit::"Release Purchase Document", 'OnBeforePerformManualCheckAndRelease''', false, false)]
    local procedure PreventRelease(var PurchHeader: Record "Purchase Header"; var isHandled: Boolean)
    begin
    var
        UserSetup: Record "User Setup"

    begin
        if userSetup.get(UserIdthen
            if userSetup."Purchase Order Release" then
                exit;
        Error('You do not have the permission');

    end;

    var
     myint : Integer;

   

}
I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,242 Super User 2026 Season 1 on at

    Yes, did you test this by installing and any issues?

  • LearnBC Profile Picture
    240 on at

    Yes. i tried.

    there is no error . but the function is not working as expected. it allows the user to Reopen. it not throwing any error and all also

  • Suggested answer
    Mohana Yadav Profile Picture
    61,242 Super User 2026 Season 1 on at

    try with "OnBeforeReopenPurchaseDoc"

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

    Hi,

    Adding more info.

    Please try this as well.

    tableextension 60100 "User Setup Ext" extends "User Setup"

    {

       fields

       {

           // Add changes to table fields here

           field(60102; "Purchase Order Release"; Boolean)

           {

               Caption = 'PO Release';

               DataClassification = CustomerContent;

           }

       }

    }

    codeunit 60105 PreventRelease

    {

       [EventSubscriber(ObjectType::Codeunit, Codeunit::"Release Purchase Document", 'OnBeforeReopenPurchaseDoc', '', false, false)]

       local procedure PreventRelease(var PurchHeader: Record "Purchase Header"; var isHandled: Boolean)

       var

           UserSetup: Record "User Setup";

       begin

           userSetup.get(UserId);

           if not userSetup."Purchase Order Release" then

               Error('You do not have the permission');

       end;

    }

  • LearnBC Profile Picture
    240 on at

    still its not working

    codeunit 60105 PreventRelease

    {

       [EventSubscriber(ObjectType::Codeunit, Codeunit::"Release Purchase Document", 'OnBeforeReopenPurchaseDoc', '', false, false)]

       local procedure PreventRelease(var PurchHeader: Record "Purchase Header"; var isHandled: Boolean)

       var

           UserSetup: Record "User Setup";

       begin

           userSetup.get(UserId);

           if not userSetup."Purchase Order Release" then

               Error('You do not have the permission');

       end;

    }

  • Suggested answer
    Mohana Yadav Profile Picture
    61,242 Super User 2026 Season 1 on at

    "Purchase Order Release" value is true or false in user setup?

  • Suggested answer
    Amit Baru Profile Picture
    3,043 on at

    Hi,

    Adding this logic.

    Create one Field in User Setup Table

    Then write code on On-open trigger of Purchase Order.

    UserSetup.get(UserId);

    if Not UserSetup.CreatedField then begin

    if Status = Status :: Release then

    error('Status is release, PO cannot be open')

    end;

    Regards

    Amit Sharma

    www.erpconsultors.com

  • LearnBC Profile Picture
    240 on at

    both are tried. its not working as expected

  • LearnBC Profile Picture
    240 on at

    now while loading the list page itself its populating the error msg

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    I recommend you use an approval flow instead. If you send the PO out for approval it can not be changed after it is approved.

    This is standard functionality and you do not have to code anything around it.

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 June Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 647 Super User 2026 Season 1

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 447 Most Valuable Professional

#3
YUN ZHU Profile Picture

YUN ZHU 366 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans