web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to get the caller object name or id

(0) ShareShare
ReportReport
Posted on by 709

Hi,

I created a controller class which eventually will be called by a menu item. I have two menu item, lets call it MenuItemDisplayA and MenuItemDisplayB, both call the same class.

This menu item display will be put in separate Form, as Form menu item button, so basically FormA will attach or set to MenuItemDisplayA and FormB will set to use MenuItemDisplayB.

What is the code in the Main method of my controller class to know which menuitem calling him ?

Because I need two different action run depend on which menuitem calling.

Thanks,

I have the same question (0)
  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi ShaqAX,

    You can use Args object passed to main method to identify the caller

    public static void main(Args _args)
    {
    
        //Check menuItemName
        if (_args.menuItemName() == menuItemActionStr(MyActionMenu))
        {
            ...
        }
        
        
        //Or check caller
        if (_args.caller() && _args.callerName() == formStr(MyForm))
        {
            ...
        }
    }

  • ShaqAX Profile Picture
    709 on at

    Hi Sergei,

    Just what I need. Thank you so much.

    BR,

  • Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at

    Note that I prefer using an enum parameter instead of checking particular menu item (or form) names. This approach allow you to define additonal menu items for the same type without having to change the controller and you safely rename objects when needed. Also, menu items / forms then can be in packages that the package containing the controllers knows nothing about.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans