Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

How to perform a task in batch job on click of form OK button?

(1) ShareShare
ReportReport
Posted on by 162
Hi ,
I am trying to perform a task in batch job which should be done when I click ok button of ax form. I have called the main method from the click method of button, but when I check the batch jobs in UI, I cannot see my batch job. 
public void clicked(){     super();      BasisController ::main(); }
Controller class 
 
 class BasisController extends SysOperationServiceController {        protected void new ()     {         super();         this.parmClassName(classStr(BasisService));         this.parmMethodName(methodStr(BasisService,processOperation));         this.parmDialogCaption(/cleanup/);         this.parmExecutionMode(SysOperationExecutionMode::Asynchronous);      }          public static void main ()     {         BasisController controller;          controller = new BasisController();         controller.showBatchTab(true);         controller.parmShowDialog(true);        controller.parmDialogCaption(/Cleanup/);                controller.startOperation();          }}
Service Class
 
class BasisService extends SysOperationServiceBase{    public void processOperation()    {        info(strFmt(/Hello/));    }}
 
Please let me know what am I doing wrong and how can I achieve the desired goal?
 
Please note : I tried 3 times for my code to look good, but everytime after updating the result, it looks same.Apologies for the same.
  • Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    How to perform a task in batch job on click of form OK button?
    Yes, I see you're using it and I'm telling you that SysOperationExecutionMode::Asynchronous doesn't run as a batch. If you want a batch, you mustn't use Asynchronous mode.
  • Harshal Jain Profile Picture
    Harshal Jain 162 on at
    How to perform a task in batch job on click of form OK button?
    Hi Martin,
    I am using this code in controller class in new method. But it did not work
     this.parmExecutionMode(SysOperationExecutionMode::Asynchronous);
     
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    How to write a code to perform a task in batch job on click of form button?
    The obvious problem is that you aren't using a batch execution mode. Use SysOperationExecutionMode::ScheduledBatch or SysOperationExecutionMode::ReliableAsynchronous instead of SysOperationExecutionMode::Asynchronous.
     
    By the way, you should use an action menu item button instead of creating a clicked() method and calling main() from there. It just requires main() method be implemented correctly - you're missing Args parameter there. It simplifies security configuration and it allows reusability of the menu item and its setup (such as the label).

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans