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 pass values through Action Menu Item

(0) ShareShare
ReportReport
Posted on by 40

Hello Dynamics Community,

I am trying to pass value from one class to another using Action Menu Item. Is there any way to achieve that?

For example,

class Class1 extends RunBase
{

AccountNum AccountNum;

#DEFINE.CurrentVersion(1)
#LOCALMACRO.CurrentList
AccountNum
#ENDMACRO

container pack()
{
return [#CurrentVersion,#CurrentList;
}

public boolean unpack(container _packedClass)
{
int version = conPeek(_packedClass,1);
switch (version)
{
case #CurrentVersion:
[version,#CurrentList = _packedClass;
break;
default:
return false;
}
return true;
}

public Object dialog()
{
Dialog dialog = super();
dialog.caption( 'Simple Dialog');
dialog.addMenuItemButton(MenuItemType::Action, 'ActionMenuItem1');
return dialog;
}

public void run()
{
info("Class1");
}

void setValue()
{
AccountNum = '4';
}

public AccountNum getAccountNum()
{
return AccountNum;
}

public static void main(Args _args)
{
Class1 class1 = new Class1();
class1.setValue();

if (class1.prompt())
{
class1.run();
}
}

}

class Class2 extends RunBase
{

    public static void main(Args _args)
    {
        Class1 class1;
        Object caller = _args.caller(); // To get the caller
        class1 = caller.runBase(); // To get object of caller class
        
        Info(strFmt("Value of AccountNum in Class1 : %1", class1.getAccountNum()));
    }

    public void run()
    {
        info("Hello");
    }

}

I have Class1 and Class2 and one Action Menu Item for Class2. Now I am calling the menu item from the dialog method and would like to pass the value(in my case AccountNum) from Class1 to Class2.

Is there any way to achieve that? Please suggest.

I have the same question (0)
  • Dynamics Community 101 Profile Picture
    310 on at

    Dear Sourav,

    This link will help you.

    dynamicscommunity101.blogspot.com/.../how-to-call-menu-item-throught-code-x.html

  • Verified answer
    Sourav Mazumdar Profile Picture
    40 on at

    Thanks Atul for your suggestion!

    After doing some research, I have found solution to my question.

    Since, I was using RunBase framework, I can get my caller's object by _args.caller().runBase().

    Hence, I updated my Class2 main method.

    public static void main(Args _args)
        {
            Class1 class1;
            Object caller = _args.caller(); // To get the caller
            class1 = caller.runBase(); // To get object of caller class
            
            Info(strFmt("Value of AccountNum in Class1 : %1", class1.getAccountNum()));
        }

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
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans