Getting error when attempting to list all tool menu items

Using the following code to list all tool menu items from the Sales workbench screen (MainController) is the name of the form.

The following code is called during the form load event: This is a very similar code which has worked from the Quote Entry and Case Entry form, Is there a way to disable / hide a menu item? - #7 by Chris_Conn - ERP 10 - Epicor User Help Forum
using Infragistics.Win.UltraWinGrid;
using System.Reflection;

	// Examine display main key for all Menus:
	var obj= MainController.GetType().InvokeMember("baseToolbarsManager", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic, null, MainController, null);
	var tools = (Infragistics.Win.UltraWinToolbars.UltraToolbarsManager)obj;

	// Commented out because this only need to explore all the menu key IDs.


	string toolnames = "";
	foreach(var t in tools.Tools)
	{
	    toolnames += t.Key +" , ";
	}
	
	MessageBox.Show(toolnames);

Error Detail

Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Field ‘Ice.Lib.Framework.UIApp.EpiHostForm.baseToolbarsManager’ not found.
Program: CommonLanguageRuntimeLibrary
Method: InvokeMethod

Client Stack Trace

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeScriptMethod(MethodInfo scriptMethod, Object[] parameters)
at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeCustomFormLoadIfExists(String methodName, Object sender, EventArgs e)
at Ice.Lib.Customization.CustomScriptManager.<>c__DisplayClassa.b__8()
at Ice.Lib.Customization.CustomScriptManager.TryActionShowExceptionBoxOrLogVerificationErrorIfException(Action action, String exceptionBoxTitle)

It’s saying that the object MainController, does not contain the member you are trying to reference (baseToolBars). You can either look at the hierarchy in customize mode, or in decomp to find the correct name of the object you are looking for.

MainController is the name of the form

Code in the script compiles successfully. The error mentioned is at run time.

That form is an EpiHostForm. The tool manager is:
this.ToolManager = AppPanel.MainToolManager;

try:
var obj= MainController.GetType().InvokeMember(“ToolManager”…

Thank you. This worked

but I need to know the names of the menus under the ActionMenu:

1 Like

I need to disable specific drop down items under the ActionMenu. What shall I used in the call MainController.GetType().InvokeMember(“ToolManager”…

Maybe you can use this shared prop to get the parent maybe or the is SystemAction tool prop:

public UltraToolbarsManager ToolbarsManager
		{
			get
			{
				if (this is SystemActionTool || this is SystemMenuTool || this is RibbonPinButtonTool)
				{
					if (this.OwnerIsToolbarInternal)
					{
						return this.OwningToolbarInternal.ToolbarsManager;
					}
					return this.OwningMenuInternal.ToolbarsManager;
				}
				else
				{
					if (this.parentCollection != null)
					{
						return this.parentCollection.ToolbarsManager;
					}
					if (this.unCustomizedParentCollection != null)
					{
						return this.unCustomizedParentCollection.ToolbarsManager;
					}
					return null;
				}
			}
		}

Or use one of these shared props to search by:

switch (name = entry.Name)
				{
				case "AccessibleDescription":
					this.accessibleDescription = (string)Utils.DeserializeProperty(entry, typeof(string), this.accessibleDescription);
					break;
				case "AccessibleName":
					this.accessibleName = (string)Utils.DeserializeProperty(entry, typeof(string), this.accessibleName);
					break;
				case "AccessibleRole":
					this.accessibleRole = (AccessibleRole)Utils.DeserializeProperty(entry, typeof(AccessibleRole), this.accessibleRole);
					break;
				case "AllowMultipleInstances":
					this.allowMultipleInstances = (bool)Utils.DeserializeProperty(entry, typeof(bool), this.allowMultipleInstances);
					this.allowMultipleInstancesInitialized = true;
					break;
				case "Category":
					this.category = (string)Utils.DeserializeProperty(entry, typeof(string), this.category);
					break;
				case "CustomizedShortcut":
					this.customizedShortcut = (Shortcut)Utils.DeserializeProperty(entry, typeof(Shortcut), this.customizedShortcut);
					break;
				case "CustomizerCaption":
					this.customizerCaption = (string)Utils.DeserializeProperty(entry, typeof(string), this.customizerCaption);
					break;
				case "CustomizerDescription":
					this.customizerDescription = (string)Utils.DeserializeProperty(entry, typeof(string), this.customizerDescription);
					break;
				case "Enabled":
					this.enabled = (bool)Utils.DeserializeProperty(entry, typeof(bool), this.enabled);
					break;
				case "IsShortcutCustomized":
					this.isShortcutCustomized = (bool)Utils.DeserializeProperty(entry, typeof(bool), this.isShortcutCustomized);
					break;
				case "MergeOrder":
					this.mergeOrder = (int)Utils.DeserializeProperty(entry, typeof(int), this.mergeOrder);
					break;
				case "MergeType":
					this.mergeType = (MenuMergeType)Utils.DeserializeProperty(entry, typeof(MenuMergeType), this.mergeType);
					break;
				case "Shortcut":
					this.shortcut = (Shortcut)Utils.DeserializeProperty(entry, typeof(Shortcut), this.shortcut);
					break;
				case "ShowInCustomizer":
					this.showInCustomizer = (bool)Utils.DeserializeProperty(entry, typeof(bool), this.showInCustomizer);
					this.showInCustomizerInitialized = true;
					break;
				case "Spring":
					this.spring = (bool)Utils.DeserializeProperty(entry, typeof(bool), this.spring);
					break;
				case "ToolTipText":
					this.toolTipText = (string)Utils.DeserializeProperty(entry, typeof(string), this.toolTipText);
					break;
				case "ToolTipTextFormatted":
					this.toolTipTextFormatted = (string)Utils.DeserializeProperty(entry, typeof(string), this.toolTipTextFormatted);
					break;
				case "ToolTipTitle":
					this.toolTipTitle = (string)Utils.DeserializeProperty(entry, typeof(string), this.toolTipTitle);
					break;
				case "Visible":
					this.visible = (bool)Utils.DeserializeProperty(entry, typeof(bool), this.visible);
					break;
				case "StatusText":
					this.statusText = (string)Utils.DeserializeProperty(entry, typeof(string), this.statusText);
					break;
				case "DescriptionOnMenu":
					this.descriptionOnMenu = (string)Utils.DeserializeProperty(entry, typeof(string), this.descriptionOnMenu);
					this.formattedDescriptionOnMenu = ToolbarsManagerUtilities.ParseFormattedText(this.descriptionOnMenu, false);
					break;
				case "Priority":
					this.priority = (int)Utils.DeserializeProperty(entry, typeof(int), this.priority);
					break;
				case "PopularCommand":
					this.popularCommand = (bool)Utils.DeserializeProperty(entry, typeof(bool), this.popularCommand);
					break;
				}

Thx. That’s a lot to chew on. I will need to do some experimenting.