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

Announcements

News and Announcements icon
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,552

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

I have the same question (0)
  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,429 on at

    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.

  • junior AX Profile Picture
    1,552 on at

    Hi Gunjan,

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

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,429 on at

    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,552 on at

    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,429 on at

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

  • junior AX Profile Picture
    1,552 on at

    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?

  • Gunjan Bhattachayya Profile Picture
    35,429 on at

    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,552 on at

    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,429 on at

    Hi,

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

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 July 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 263 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Subra Profile Picture

Subra 235 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans