Dexterity: Accessing a form menu from a global script

Patrick Roth

Every so often, a developer might need to check or set the status of a form level menu item.  Say, for instance, the goal would be to make sure that the "Add Item" menu item of the Sales Transaction Entry Options menu was checked.

From a global procedure - your trigger handling script most likely - you enter the following Dexterity code:

     check menu Options of form SOP_Entry,1;

When you try to compile this, the compiler will fail with the errors:

     Unknown Identifier 'Options'.
     Type incompatability 'check requires a list field or menu'.

In the past, what I've seen developers do is make an alternate form just so that they can make a new form level function or field level change script that does have access to the menu item. While that would work, it obviously isn't the best solution if you don't have to modify the form for other reasons.

The code below is what I have referenced in a newsgroup post as "the menu reference trick" and the technique that I used for the Additem.cnk way back when.

Code Example

 

local reference m;

{Get the reference to the menu - this is the 'trick'}
assign m as reference to menu Options of form SOP_Entry;

{Look if the 'Add Item' is marked or not by dereferencing it.  
If not marked, give a warning and then set it.  
Yes the check is redundant but this example
shows we have full access to the form level menu item.}
if checkedmenu(menu(m),1) = false then
 warning "The 'Add Item' menu item is not checked.";
 {Next check the first menu item in the list - Add Item.}
 check menu(m),1;
end if;

This method will also work for 3rd party menu items provided you use the code within the execute() function.

Best Regards,
Patrick
Developer Support

// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, https://opensource.org/licenses/ms-pl.html.)