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

Run batchJob(sysOperation) by code x++

(0) ShareShare
ReportReport
Posted on by 1,550

So i want to create a batch job task in the UI and assign a class for it to run.

What should my class contain to make the batch job task run? should i create a controller and service class and assign the controller class to it? because i did this but i couldn't find my controller class in the classes dropdown

pastedimage1600545099686v1.png

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Run batchJob(sysOperation) by code x++

    Hi,

    I am not sure since I haven't tried doing this before. I will check if this can be done.

  • junior AX Profile Picture
    1,550 on at
    RE: Run batchJob(sysOperation) by code x++

    Hi Gunjan,

    Thanks alot for your help.

    May i ask another thing, in my service class, i'm exporting an entity (with incremental push) and sending the file generated to a certain destination. Now when there is no content in the generated file, the destination receives a file with no content, how can i check the content if it's empty or not before sending to destination?

    DMFEntityExporter exporter = new DMFEntityExporter();
    fileId = exporter.exportToFile(entityName,
    definitionGroupName,
    '', //Optional: ExecutionID
    "XML-Element", //Optional::SourceName
    #FieldGroupName_AllFields, //Optional field selection
    query.pack(), //Optional: Filtered Query
    curExt() //Optional: DataAReaId
    );

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Run batchJob(sysOperation) by code x++

    Hi,

    You have to change the job status to Waiting and set a recurrence for the job. That should start it.

  • junior AX Profile Picture
    1,550 on at
    RE: Run batchJob(sysOperation) by code x++

    Hi Gunjan,

    Thanks it started appearing after the full build. However what should the status of the task be? Right now it's withhold and the batch didn't start even though i scheduled it for now. Should i change it to waiting or how can i make it start?

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Run batchJob(sysOperation) by code x++

    Did you try doing a full build of the model? If not, please do that and try again.

  • junior AX Profile Picture
    1,550 on at
    RE: Run batchJob(sysOperation) by code x++

    Hi Gunjan,

    I tried adding the parameter but it's still not appearing.

    [SysOperationJournaledParameters(true)]
    class TestController extends SysOperationServiceController
    {
        /// 
        ///   What method to call from the service class
        /// 
        protected void new()
        {
            super(classStr(TestService),methodstr(TestService,export),SysOperationExecutionMode::Synchronous);
        }
    
        /// 
        ///
        /// 
        public static TestController construct()
        {
            TestController controller = new TestController();
            controller.parmShowDialog(false);
            controller.parmShowProgressForm(false);
            return controller;
        }
    
        public static void main(Args _args)
        {
            TestController controller = TestController::construct();
            controller.startOperation();
        }
    
        protected ClassDescription defaultCaption()
        {
            return "Export";
        }
    
    }

    class TestService extends SysOperationServiceBase
    {
        public void export()
        {
            //logic
        }
    }

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Run batchJob(sysOperation) by code x++

    Hi,

    Not sure why you want to add batch tasks this way. The above mentioned method will create a new job and will add to the tasks as well.

    In any case if you want the class to appear in the batch task drop down, add this attribute -

    [SysOperationJournaledParameters(true)]

    You can check class "WHSReleaseToWarehouseController" as an example.

  • junior AX Profile Picture
    1,550 on at
    RE: Run batchJob(sysOperation) by code x++

    Hi Gunjan,

    The requirement is to put it there in batch job tasks.. can you help?

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Run batchJob(sysOperation) by code x++

    Hi,

    You can just setup the batch job by running the action menu item that you would have created for the class and going to the "Run in the background" section

    Here you set batch processing to "Yes" and set the recurrence.

    pastedimage1600545656275v1.png

    This will setup the batch job.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,923 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,788 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans