back to top

Working with SalesLogix MenuItems

So a question was posted in the SalesLogix Business Partner news groups about working with MenuItems, and specifically with the PopupMenu property of the SalesLogix DataGrid control. I thougt it was worth while to post my reply here as well.

I am trying to get a reference to one of the items in a grids PopupMenu Items collection. I would like to obtain the reference by using the Items caption.  (ex. “My Sub Menu”).

‘attempt to access collection via “name” (i.e. Caption text)
Set oItem = grdControl.PopupMenu.Items(“&Edit…”)  ‘<– fails
Set oItem = grdControl.PopupMenu.Items(“Edit…”)  ‘<– fails
 
‘attempt to use Find method that appears to take a Caption text as an argument
Set oItem = grdControl.PopupMenu.Items.Find(“&Edit…”)  ‘<– fails
Set oItem = grdControl.PopupMenu.Items(“Edit…”)  ‘<– fails

Here is my reply:

Well, you could always just iterate though the items. Checking the caption property of each to see if it is the one you are looking for (and I’d replace off any ‘&’ from the caption since you could not reliably know where it is in the string as they are often auto-assigned).

Wouldn’t be too bad – not like you’re going to have a thousand items to iterate through, probably only looking at a handful of items tops. I did something similar to this where I dynamically filled the PopupMenu based on the fields that appeared in the query the grid was bound to. Ran fast. Similarly, you’d see really very little difference in speed if you iterated though them to find the one you’re looking for. Know what I mean?

However, for readability of your code it would be much nicer to be able to just reference an item in the collection. I hate to tell you this. It works for me (with a caveat – keep reading).

I have a DataGrid PopupMenu with 3 custom items in it, Tester 1, Tester 2, and Yeye Tester. I run this code, and it works fine.

Sample Menu
    – Tester 1
    – Tester 2
    – Yeye Tester

Dim item

    Set item = DataGrid1.PopupMenu.Find(“Yeye Tester”)
    If Not item Is Nothing Then
        MsgBox “I found ” & item.Caption
    Else
        MsgBox “not found”
    End If

The reason why this works is that all MenuItems are top level MenuItems. Here’s probably why it is failing for you. The “Find” method applies to the collection for the current MenuItem only. Each MenuItem has an “Items” collection of children MenuItems. Each subitem is contained in the collection of it’s respective parent. Opening the SalesLogix Controls with an object browser, you’ll see that the Find method is a method of the MenuItem, not of the PopupMenu. This leads me to believe it applies only to that particular MenuItem’s “Items” collection. If you wanted to use Find in the case with sub groups of menu items you’d actually have to iterate through all top level items to call Find for each of their Items collections. So the Find method of the PopupMenu is searches it’s own immediate Items collection. In your case, it is likely that the MenuItem you’re looking for is a sub-item of another MenuItem. So, when searching the Items collection of a given MenuItem, you need to recursively run down the tree of MenuItems in the collection, checking also each of their Items collections as well. One thing to point out here, the PopupMenu property of the SalesLogix DataGrid control is of type MenuItem, it is not of type PopupMenu as it’s name would imply. So as the PopupMenu property of the DataGrid is nothing more than a MenuItems object, when you call Find on PopupMenu, you are simply calling Find on the top level MenuItems only (or basically the MenuItems that exist in the top MenuItem (the one named PopupMenu exposed on the grid)

Sample Menu
    – Tester 1
    – Tester 2
        – Sub Tester 2a
            – Yeye Tester
            – Bobo Tester
        – Sub Tester 2b
    – Tester 3

Let’s say we want to find ‘Yeye Tester’. What you need to do is recursively move down the tree calling Find for each MenuItem. Here’s a sample that should work for you.

Function MenuItemFind(popupmenu, menucaption)
Dim item
Dim i
       
    Set item = popupmenu.Find(menucaption)
    If Not item Is Nothing Then
        Set MenuItemFind = item
        Exit Function
    Else
        For i = 0 To popupmenu.Count – 1
            On Error Resume Next
            Set item = MenuItemFind(popupmenu.Items(i), menucaption)
            If Not item Is Nothing Then Set MenuItemFind = item
            On Error GoTo 0
        Next
    End If
End Function

Basically, this does just what is needed. A recursive function to call find on the Items collection of each MenuItem in the tree. Now to use it, all you need to do is make a single call:

Dim item

    Set item = MenuItemFind(DataGrid1.popupmenu, “Yeye Tester”)
    ‘It is a good idea to make sure it actually found the MenuItem with the caption supplied
   
    If Not item Is Nothing Then
        MsgBox “I found ” & item.caption
    Else
        MsgBox “Not found”
    End If
   

Well, that is it in a very long and drawn out nutshell. Have fun.

-Ryan Farley

Contact Customer FX for your CRM project
We let our expertise speak for itself - let us know how our all-star team can help on your CRM project
About the Author
Ryan Farley
Ryan Farleyhttps://customerfx.com/article/author/ryanfarley/
Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Infor CRM SLX 10.0: Delegate Ownership Changes for “Everyone” Records

Learn how the new EveryoneOwnerAssignment secured action in Infor CRM SLX 10.0 allows designated users to change ownership of Everyone-owned records without requiring Administrator access.

Related Articles

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Related Videos