Search code examples
axaptax++dynamics-ax-2009

Is code running in client or as batch job?


Is there any way to determine whether the code is being executed in the client or in a batch job ? I thought of using curUserId and checking if the user is the one we use for batch jobs, but this approach fails if the user is ever changed.

I'm trying to modify the update method of table VendTable with a Yes/No dialog when it's run into a client, but I don't want this happening when the code runs as batch.

Any ideas ?


Solution

  • On your batch class that extends runbasebatch, you can use this.isInBatch(). This will return true if code runs in batch and false if not running in batch. You can then pass this as a parameter to other classes. (I would recommend doing it this way).

    One note though, you shouldn't be showing a dialog in the update method of the VendTable table because you should never have user interaction in a transaction which I assume will be the case.

    If you want to have user interaction when a user writes a record on a form, try overwriting the write method of you form datasource. This will be executed when a record is written (inserted, updated). You can ask for user input here. For an example, check the purchtable form (purchtable ds, write method), it should contain something similar (it asks to copy fields from header to line)