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

Notifications

Announcements

No record found.

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 224

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
    60,993 Super User 2025 Season 2 on at

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

  • LearnBC Profile Picture
    224 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
    60,993 Super User 2025 Season 2 on at

    try with "OnBeforeReopenPurchaseDoc"

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 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
    224 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
    60,993 Super User 2025 Season 2 on at

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

  • Suggested answer
    Amit Baru Profile Picture
    3,037 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
    224 on at

    both are tried. its not working as expected

  • LearnBC Profile Picture
    224 on at

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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans