Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / SysOperation synchrono...
Finance forum

SysOperation synchronous options

(0) ShareShare
ReportReport
Posted on by 3,542

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:

Screenshot-2019_2D00_05_2D00_29-at-09.55.14.png

I'd rather have something in the direction of this:

2768.capture3.png

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

  • Pete Alberts Profile Picture
    3,542 on at
    RE: SysOperation synchronous options

    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:

    1. In the Controller (which extends SysOperationServiceController), override canRunInNewSession()
    2. In the Operation class add a member SysOperationProgress.
    3. Initialise the member before the process starts

    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():

    Screenshot-2019_2D00_10_2D00_18-at-12.09.30.png

    A working example on how to initialise SysOperationProgress:

    Screenshot-2019_2D00_10_2D00_18-at-12.11.17.png

  • Pete Alberts Profile Picture
    3,542 on at
    RE: SysOperation synchronous options

    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.

  • Pete Alberts Profile Picture
    3,542 on at
    RE: SysOperation synchronous options

    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 :)

  • Pete Alberts Profile Picture
    3,542 on at
    RE: SysOperation synchronous options

    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.

  • Pete Alberts Profile Picture
    3,542 on at
    RE: SysOperation synchronous options

    I lied. It refreshes.

  • Pete Alberts Profile Picture
    3,542 on at
    RE: SysOperation synchronous options

    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.

  • Verified answer
    Martin Dráb Profile Picture
    232,064 Most Valuable Professional on at
    RE: SysOperation synchronous options

    Consider using controller's method called afterOperation(). It has some documentation in SysOperationServiceController class.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,289 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,064 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans