Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Run a job in background after form is closed

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
    Leo Chen 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
    Martin Dráb 225,526 Super User 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
    Ahsan Baig 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
    Martin Dráb 225,526 Super User 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).

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,835 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans