Hi, Readers.
In Dynamics 365 Business Central: Dynamic Visibility of Controls (Hide and show fields dynamically) we have discussed how to dynamically hide and show fields.
Today I would like to discuss a similar topic, whether it is possible to hide and show actions dynamically. In conclusion, this is possible. And there is similar behavior in the standard. For example, Item Charge Assignment action on the Sales Order Subform page.
If you are selecting a sales line of type Charge (Item), you can click this action, but if you select another type, such as Item, this action is is grayed out (not clickable).
In the standard, the Enabled Property is used. The Boolean field on the page can be either a true/false Boolean or a Boolean expression, such as Rec.”Sales (LCY)” > 5000 or Rec.Type = Rec.Type::”Charge (Item)”.
So if we want to hide or show the button dynamically, we can use the Visible Property. For example, the Show My Message action is displayed when the type is Charge (Item), and is hidden otherwise.
Test video:
Source code:
pageextension 50222 SalesOrderSubformExt extends "Sales Order Subform"
{
actions
{
addfirst("&Line")
{
action(ShowMyMessage)
{
ApplicationArea = All;
Caption = 'Show My Message';
Image = ShowWarning;
Visible = Rec.Type = Rec.Type::"Charge (Item)";
trigger OnAction()
begin
Message('Hello World');
end;
}
}
}
}
Of course, this can also be done on the main page (Header). For example, the action is displayed only when the order status is Released.
Test video:
Source code:
pageextension 50223 SalesOrderExt extends "Sales Order"
{
actions
{
addfirst(processing)
{
action(ShowMyMessage)
{
ApplicationArea = All;
Caption = 'Show My Message';
Promoted = true;
PromotedCategory = Process;
Image = ShowWarning;
Visible = Rec.Status = Rec.Status::Released;
trigger OnAction()
begin
Message('Hello World');
end;
}
}
}
}
So does this also work with standard actions? Yes of course. Let’s look at another simple example. Only sales orders in the Released status can be printed.
Test video:
Source code:
pageextension 50223 SalesOrderExt extends "Sales Order"
{
actions
{
modify("Print Confirmation")
{
Visible = Rec.Status = Rec.Status::Released;
}
}
}
Of course, you can also use variables to control, for example,
Test video:
Source code:
pageextension 50223 SalesOrderExt extends "Sales Order"
{
layout
{
addafter(Status)
{
field(AllowPrint; AllowPrint)
{
ApplicationArea = All;
Caption = 'Allow Print';
ToolTip = 'Check to allow printing';
}
}
}
actions
{
modify("Print Confirmation")
{
Visible = AllowPrint;
}
}
var
AllowPrint: Boolean;
}
Very simple, give it a try!!!😁
END
Hope this will help.
Thanks for reading.
ZHU
コメント