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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Menu item's EnumParameter not working in batch?

(0) ShareShare
ReportReport
Posted on by 1,087

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

  • Verified answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    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.

  • vv1984 Profile Picture
    1,087 on at

    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
    101,172 Moderator on at

    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
    1,087 on at

    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!

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 539 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 366 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 197

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans