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 :
Microsoft Dynamics AX (Archived)

[SysOperationFrameWork] Call MenuItem/Job by X++

(0) ShareShare
ReportReport
Posted on by

Good morning,

i developed several jobs using the SysOperationFrameWork. This jobs can be started by simply clicking the menu item or by X++ during certain processes.

Now i wonder if i can use the "old" MenuFunction method to call this job by code because the calling procedure for SysOperation-jobs differs from RunBaseBatch. My job takes a WaveId as a parameter.

How would you call a SysOperation by X++?

Regards

Nils

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Calling MenuFunction from code is exactly the same: create an instance (passing the name and type of the menu item) and call run() (passing Args). Args will be filled in in exactly the same way too; it doesn't matter if your class uses RunBase or SysOperation framework.

    Maybe your question isn't about menu item and MenuFunction and you simply don't know how to pass parameters from Args to your data contract. One possible approach is passing Args (in main()) to you controller through parmArgs() and then using it in initializeParameters(). Find your contract and set values from Args as needed.

  • Community Member Profile Picture
    on at

    Hi Martin,

    thanks for reply. Yes i'm not sure how to pass attributes from Args to the DataContract. I will try your approach and let you know if it works.

    Regards

    Nils

  • Community Member Profile Picture
    on at

    The MenuFunction/Args-variant didn't work for me. I got an error in the controller class because it had no DataContract and i didn't find a way to pass a contract to a controller. Maybe i missed something?

    This code worked out finally. This way i bypass the menu item, dialog etc.

    KVCleanupSorterService service = new KVCleanupSorterService();
    KVCleanupSorterServiceDataContract contract = new KVCleanupSorterServiceDataContract();
    
    contract.parmWaveId(waveId);
    service.cleanUpSorter(contract);


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

    Your code works, but it doesn't use SysOperation framework at all. It's a mere method call. It doesn't move execution to server tier, it doesn't run in CIL, it doesn't validate the contract, it doesn't support asynchronous and batch execution and so on. Simply put, all the reasons why we use SysOperation framework are missed by your implementation.

    I can't comment on your problem with the controller, because I have no idea what you implemented.

  • Community Member Profile Picture
    on at

    I implemented a controller, data contract, service and a menuitem. Normally the job is run manually. Now i need the same functionality in another process and i was looking for is a way to reuse the funtionality already implemented in the service class.

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

    That doesn't really explain your code that caused "an error in the controller class because it had no DataContract".

  • Community Member Profile Picture
    on at

    Edit:

    In my case i just needed the funtionality of a method, not the other things provided by the SysOperationFramework. I wasn't clear about this.

  • Community Member Profile Picture
    on at

    Here is an example of what happens if i try to run the job via MenuFunction. I think i have to pass a DataContract somehow but don't know where.

    static void Job26(Args _args)
    {
        Args args = new args();
        
        args.record(WHSWaveTable::find("CHWAWV0000000093"));
        
        new MenuFunction(menuitemActionStr(KVCleanupSorterService), MenuItemType::Action).run(args);
    }

    Error:
    6735.error.png

  • Verified answer
    Community Member Profile Picture
    on at

    Try this

    SalesTable salesTable= SalesTable::find('QFCA-000002');  

    Args args = new Args();     

       

    args.record(salesTable);     

    args.caller();     

    new MenuFunction(menuitemDisplayStr('SalesLine'), MenuItemType::Display).run(args);

  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    "No metadata class defined for data contract object" means that your data contract is invalid. The most common reason is forgetting to decorate the contract class with the DataContractAttribute.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans