Dexterity: Accessing a form menu from a global script


Patrick Roth - Click for blog homepageThis is a reposting of an article Patrick Roth originally wrote on my Developing for Dynamics GP blog.

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, http://opensource.org/licenses/ms-pl.html.)

This article was originally posted on the Developing for Dynamics GP Blog and has been reposted on http://www.winthropdc.com/blog.

3 thoughts on “Dexterity: Accessing a form menu from a global script

  1. Yes you can set up a reference to whatever you like.  However most of the time you don’t need to because you can just reference a field directly in your global script.  Of course using references to fields, windows, etc does have other practical uses.

    Like

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.