Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Run a job in background after form is closed

(0) ShareShare
ReportReport
Posted on by 30

Hi,

I have wrote a job that update values in many tables (Updating takes time as there are many records that are updated)

The job should run when a form is closed (the job takes value from the form as parameter).

The job is executed on form close method but it takes time which causes delay on form close.

One solution is to run this job on batch.

But user wants to update tables at run time.

Is there is a way to run job at background like a batch when the form closes and there is no delay at form close method.

(i wrote a batch job that runs on form close but user does not what to show batch job dialogue.)

Thanks

  • Suggested answer
    Leo Chen Profile Picture
    on at
    RE: Run a job in background after form is closed

    You may need a timer. Try setTimeOut(). This will not block the form closure but can execute any job you want.

    community.dynamics.com/.../refresh-form-automatically-after-specific-time-interval-in-ax2012

    stackoverflow.com/.../settimeout-and-local-function

  • Martin Dráb Profile Picture
    231,947 Most Valuable Professional on at
    RE: Run a job in background after form is closed

    You said that you don't want any dialog, but also that you have a form where users set parameters for the function, which is logically a dialog for the function, isn't it?

    You have two main options:

    1) You'll change your design to how things are normally done in AX 2012, i.e. you'll use SysOperation framework. You'll either generate a dialog at runtime (maybe it'll be automatically generated for you from a data contract), or - if it can't be done by any other way - you'll use your form as the SysOperation dialog.

    2) Or you'll have your dialog as a separate form, you'll create a controller for your logic from code and you'll also populate the data contract from code. Hiding the dialog isn't a problem - it's controlled by showDialog variable in controllers. If you decide to do it this way, make sure you don't call your logic on close(). Allow users to cancel the processing, the same way as you can press Cancel in normal dialogs.

  • Ahsan Baig Profile Picture
    30 on at
    RE: Run a job in background after form is closed

    1) By real time i mean as soon as form closes. I want to run code at background without causing delay to the user.

    2) I am using Microsoft Dynamics AX 2012 R3.

    i do not want any dialogue be shown to the user. (just when form closes my  job runs without causing a delay to the user)

  • Suggested answer
    Martin Dráb Profile Picture
    231,947 Most Valuable Professional on at
    RE: Run a job in background after form is closed

    I'm not sure what you mean by "at run time". All code runs at run time by definition.

    Anyway, there is a whole framework for this kind of tasks: SysOperation framework (and the older one, RunBase framework). It collects user input from a dialog and executes business logic, which can be done in four modes: Synchronous, Asynchronous, ReliableAsynchronous and ScheduledBatch. Maybe you believe that ScheduledBatch is your only option, while just switching to Asynchronous or ReliableAsynchronous may be the solution for you.

    By the way, can you please clarify which version are you talking about? You attached tags for both AX 2012 and D365. I also changed the category to Development / Customization / SDK (from Administration and Setup + Sales and Marketing).

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... 293,274 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,947 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans