How to disable enable action on page dynamically on user selection in Business central

 

Disable / Enable Action  on Page with some Value.

I came up to an requirement of enabling and disabling action coming on business central page and that should be on basis of some value i.e. I have list page of variants and i want to disable my action (Xyz) on that page if user has selected some variant named as Abc and if not then it should be enable likewise.

Note :
I used the property "Enabled" of actions in business central and acquired my need by binding it to some boolean variable that is having value true or false on some condition. And doing that whole story in page trigger 
onaftergetcurrrecord()
that is the trigger which is fired every time when user does some selection on list. 
Here is the code snippet of my page extension.

Code example :
pageextension 50143 VariantListPageExt extends "Item Variants"
{
    layout
    {
        // Add changes to page layout here
        addafter(Description)
        {
            field(WooNo; Rec.WooNo)
            {
                ApplicationArea = All;
            }
            field(SyncStatus; Rec.SyncStatus)
            {
                ApplicationArea = All;
            }
        }
    }

    actions
    {
        addlast(Processing)
        {


            action(WooCommerceSync)
            {
                Caption = 'Sync Attribute';
                ApplicationArea = All;
                Image = Process;
                Enabled = ACTIONCHECK;

                trigger OnAction()
                begin

                    CurrPage.SaveRecord();
 end
                    

            }

        }
    }

    var
      
        ACTIONCHECK: BOOLEAN;

    trigger onaftergetcurrrecord()

    begin
        if (Rec.SyncStatus = 'Sync Done')
        then begin
            ACTIONCHECK := false;
        end
        else begin
            ACTIONCHECK := true;
        end;
    end;
}

Comments

Post a Comment

Popular posts from this blog

Reading json data in Business Central

Consume Rest API in Business Central Code with Basic Auth

How To do Hashing HMAC RSA 1 algorithm or cryptography in Microsoft Business Central | AL Code