I have a code unit that I want to be able to run either directly or through a batch job in Business Central. I want to have the flexibility to choose how to run the code unit based on my preference without having to modify the code unit each time.
The reason for this is that I don't want the screen to block every time I run that code unit. I want to be able to choose to run it in the background or in a queue so that it doesn't interfere with my work.
What is the best approach to accomplish this? Should I add my code unit to a job on the Job Queue Entries page, If yes, then how can I manage it to run whenever I want?
I would appreciate any guidance or help.
Thank you.
I have created the job queue for my codeunit manually through code and have been able to run it manually at once using RunJobQueueEntryOnce. However, I am still facing an issue where it pops a dialog box to run in the foreground, which blocks my screen when running. What I really want is to run it in the background without any dialog box or schedule it to run later so that it goes into a queue and doesn't run immediately.
Does anyone have any suggestions or like what I'm doing wrong here?
Thank you NAV_with_Narang, YUN ZHU, Nitin Verma, Manish Sharma for your response, considering your suggestions of the first option of creating a button on a page and adding the option to run the codeunit in a job or directly seems like the better option for my use case.
As for running the job, I can either create a new job queue entry and runs it.. when the user selects the option to run the codeunit in a job, or I can manually create the job queue entry beforehand and run that job queue entry at once...what should be the best option... and how can I run the queue without scheduling it.. to run..
Regards
You can check task scheduler to create you job queue and execute it in background.
But you would be needing a action button somewhere to start this activity.
Shopify has this kind of scheduling for products, you can check that as an example.
Hi peopleeater ,
There are two ways and 1st you can create a button on the required page and write your logic how you want to execute that codeunit and 2nd option you can create a report without any dataitem and write your logic on PostReport to run the Codeunit based on the boolean field, and that boolean field you can put on report's request page, so that when you run that report, you can put that boolean value true based on your requirement and run the report and that logic of PostReport will trigger.
Thanks.
Hi, maybe my understanding is wrong, but Codeunit can be set in Job Queue, you can put your code in trigger OnRun(), so that it can run directly.
Hope this helps.
Thanks.
ZHU
You can create a button on a page, which will create a Job Queue Entry in the background and start running immediately without interrupting your front UI. You can also write the code in such a manner that it deletes this JQ once it has completed it's process. There are examples of creation of Job Queues when you use BC <> CRM OOB integration
You can also use Page background tasks as illustrated here by Microsoft learn.microsoft.com/.../devenv-page-background-tasks
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,151 Super User 2024 Season 2
Martin Dráb 229,963 Most Valuable Professional
nmaenpaa 101,156