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...
Answered

AL Code Help

(2) ShareShare
ReportReport
Posted on by 224

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;

        }

    }
}

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,698 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
    224 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,698 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
    994 on at

    Hi,

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

    7318.Capture2.PNG

  • LearnBC Profile Picture
    224 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,698 Moderator on at

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

  • LearnBC Profile Picture
    224 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,698 Moderator on at

    share your every line of code here.

  • LearnBC Profile Picture
    224 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,698 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

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