Announcements
I know there are hundreds of posts about this. I could not find one that answers my question.
I have a working job for which I used the SysOperation framework.
The job updates table XYZSomeTable. The menu item XYZSomeJob that calls the controller is somewhere on a menu and on the XYZSomeForm.
The new requirement from consultant X is that the job should refresh datasource XYZSomeTable if the job is called from XYZSomeForm after it completes. My first thought was to reject the request. I have a vague understanding that it is not possible without massive restructuring. And then the job has the potential to become very time consuming. With contoso data it completes within a few dozen seconds, which I am quite sure will not be the case in live.
I am currently trying to achieve this. Any suggestions?
My solution A
If the job is called from the form the user should have the option to run it synchronously or asynchronously. I don't know how to do that in a user friendly way. So I reverted to run the job synchronously unconditionally if called from the form. But then the form just freezes. I want some progress dialog which I could not achieve with SysOperation in synchronous mode.
My solution B - current
I noticed there is a method parmShowProgressForm. Which I am using. It looks like this:
I'd rather have something in the direction of this:
http://devblog.sertanyaman.com/2017/03/14/synchronous-and-asyncronous-operations-in-ax7/
Is it possible to get that dialog using SysOperationServiceController? Or will I have to use SysOperationSandbox?
Nonetheless, that is working. But I am worried about the code - I have another vague idea that this code could cause issues:
static void main(Args _args) { XYZMassiveController controller = new XYZMassiveController(classStr(XYZMassiveOperation),
methodStr(XYZMassiveOperation,operation)); controller.parmArgs(_args); controller.parmShowProgressForm(_args.callerName() == formStr(XYZSomeForm)); controller.startOperation(); if (controller.parmShowProgressForm() && _args.callerName() == formStr(XYZSomeForm)) { FormRun formRun = _args.caller(); FormDataSource formDataSource = formRun.dataSource(formDataSourceStr(XYZSomeForm,XYZSomeTable)); formDataSource.research(); } }
What I noticed is if (on the front end) one waits for the progress form the form datasource will refresh, if one does not, it doesn't.
Thanks for reading
I needed to do this again. So I followed my own instructions from this post and still struggled for 2 hours. So here is a step by step:
And then I think the job's execution mode should be set to SysOperationExecutionMode::Synchronous (not sure - didn't test anything else than Synchronous).
How to override canRunInNewSession():
A working example on how to initialise SysOperationProgress:
If anyone is wondering how to produce that progress form for SysOperation...
You can use SysOperationProgress in the operation class. Examples include InventSumSummarizeService (line 110) and a more detailed version HcmPositionForecastCopyService.
This has been a monologue to say the least. Thanks Martin. I guess your silence on the other questions meant I am on the right route...
And then I can't mark my own replies as answers anymore. I guess that change was made specially for me :)
So I have the reason for being worried about that code. The process runs asynchronously, thus the FormRun object could possibly no longer exist when the datasource is refreshed. I tested it by closing the form before the operation completes and then stepping through afterOperation(). Somehow the form and datasource still exists and no error gets thrown. It does not make sense to me. But I am very thankful indeed for this magic.
I lied. It refreshes.
Thanks I restructured and moved to afterOperation()
I am interested in why the form datasource does not refresh if the progress form is closed before the operation completes. I stepped through it and the formDataSource.research() part still completes successfully. But still no refresh.
Consider using controller's method called afterOperation(). It has some documentation in SysOperationServiceController class.
André Arnaud de Cal...
293,289
Super User 2025 Season 1
Martin Dráb
232,064
Most Valuable Professional
nmaenpaa
101,156
Moderator