Dynamic Menu Text

In Acumatica, we have the ability to easily create actions and add them to the menu. While this is a great feature, sometimes we want to provide a different “step forward” in the flow of work based on conditions within the current record. To provide a variety of actions for each possibility, the Actions menu could become quite lengthy with many options always disabled. Fortunately, there is an easy solution.

To set the menu text, simply use the SetCaption method on the action and pass in the desired text. For simplicity, the following sample will use an if… then… else to demonstrate the syntax. The menu text for the example is hardcoded, but it is highly recommended to use the Messages class so that standard localization can be used as well.

protected virtual void _(Events.RowSelected<MyDAC> e)
{
	MyDAC row = (MyDAC) e.Row;

	if(condition 1)
	{
		myGenericAction.SetCaption("Condition 1 Menu Text");
	}
	else if(condition 2)
	{
		myGenericAction.SetCaption("Condition 2 Menu Text");
	}
	else
	{
		myGenericAction.SetCaption("Default Menu Text");
	}
}

In the RowSelected event, we must check each condition and set the menu text accordingly. In the myGenericAction action, we would need to test each condition in a similar manner and execute the appropriate business logic by condition.

Happy Coding!

Leave a Reply