Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Menu item's EnumParameter not working in batch?

Posted on by 1,085

Hi,

I have a class which runs in batch. The class is called by different menu items, for example:

-MenuItem1: EnumTypeParameter=myEnumParameter, EnumParameter = "Version1"

-MenuItem2: EnumTypeParameter=myEnumParameter, EnumParameter = "Version2"

The main method retrieves the value of the EnumParameter:

static void main(Args args)
{
    MyClass    myClass;
    ;

    myClass = MyClass::construct();

    if(args && args.parmEnum())
    {
        myClass.parmMyEnumParameter(args.parmEnum());
    }

    if (myClass.prompt())
        myClass.run();
}

The run method of the class checks the value of the EnumParameter to understand which operations must be executed:

switch(myEnumParameter)
    {
        case myEnumParameter::Version1:
            this.runVersion1();
            break;

       case myEnumParameter::Version2:
            this.runVersion2();
            break;


        default:
            info("default");
            break;
    }

When i run it in client mode it all works fine: the value of enumParameter is read correctly and the corresponding method "runVersion" is executed.

In batch mode looks like the enumParameter's value is not retrieved and the execution falls down into the "default" branch of that switch statement.

I think I've tried every combination of the RunOn property on both the action MenuItem and the Class. Is there something i'm forgetting here?

Thanks in advance for your help

regards

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Menu item's EnumParameter not working in batch?

    The main method IS "ignored" (= not run)  in the batch. But when you set up the batch (via the menu item), the main method is run, and you can set the class variable, which is then packed to CurrentList and unpacked when the batch runs.

  • vv1984 Profile Picture
    vv1984 1,085 on at
    RE: Menu item's EnumParameter not working in batch?

    Thank you,

    yes, the only missing point was to add the variable in the [tag:CurrentList] macro.

    I was misunderstanding, I though the main method was completely ignored by the batch execution, but it is not. I only had to store that variable somewhere before entering the batch mode.

    Thanks!

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Menu item's EnumParameter not working in batch?

    Hi win32,

    you might have missed part of my answer. Please focus on the third point: the variable must be added to the #currentList so that it's packed and unpacked for the batch.

    Remember that the original object doesn't exist when the batch runs. It disappears after you click OK one the dialog and the relevant data is stored to the batch tables. All variables that you need in the batch must be stored in the packed variables (which are listed in [tag:CurrentList] macro if you're using RunBaseBatch). When the batch runs, the system has to create a new instance of your class, and it uses the packed data to set the relevant variables.

    You can look at Tutorial_RunBaseBatch class if you want a tutorial.

  • vv1984 Profile Picture
    vv1984 1,085 on at
    RE: Menu item's EnumParameter not working in batch?

    Hi,

    thanks for your reply.

    I've already added a global variable in my class to store the parameter's value. Also the parmMethod is already in my class:

    MyEnumParameter parmEnumParameter(MyEnumParameter _myEnumParameter= myEnumParameter)

    {

       myEnumParameter=   _myEnumParameter;

       return myEnumParameter;

    }

    But still I can't find a way to read the menuItem's parmEnum value from the args object of my class.

    How do I retrieve (and in which method of my class) that value?

    Thanks

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Menu item's EnumParameter not working in batch?

    Whatever values you need when it runs in the batch, you need to store with the packed batch variables.

    I guess you are using RunBaseBatch framework? Then you need to add following things:
    - a class variable for the enum parameter

    - a parm method that you can use to set the class variable from main method

    - the variable must be added to the #currentList so that it's packed and unpacked for the batch

    Most likely you're missing the last part, and that's why the system doesn't remember the value of this variable when the class is instantiated by the batch framework.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,126 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans