web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Async not working as required

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

I have a customized code not made by me that opens a dialog and some logic is done when ok is clicked.

I want to made an extension of this method and put code after super where i don't want their dialog (logic) to wait for my code until it closes. 

Which means their dialog must close right after their logic ends and my new logic can run in the background.

I think what I'm trying to achieve means that  I need to create a batch with Async right? but I tried to debug and the dialog didn't close directly and the debug went to my controller and waited for it to finish before the dialog was closed

so here's what i did: 

[ExtensionOf(classStr(class1))]
final class classAA_Extension
{
    protected void method1()
    {
        next post();
        Controller controller = Controller::construct(Id);
        controller.startOperation();
    }
}

contract

[DataContractAttribute]
class Contract
{
    Id id;

    [DataMemberAttribute]
    public Id Id(Id _id = id)
    {
        id = _id;

        return id;
    }

}

Controller

/// 
/// 
/// 
[SysOperationJournaledParameters(true)]
class Controller extends SysOperationServiceController
{
    /// 
    ///   What method to call from the service class
    /// 
    protected void new()
    {
        super(classStr(Service),methodstr(Service,Demo),SysOperationExecutionMode::Asynchronous);
    }

  
    public static Controller construct(Id _Id = "")
    {
        Controller controller = new Controller();
        controller.parmShowDialog(false);
        controller.parmShowProgressForm(false);
        Contract  contract =  controller.getDataContractObject();
        contract.Id(_Id);
        return controller;
    }

    /// 
    /// main method of the controller class
    /// 
    /// args
    public static void main(Args _args)
    {
        Controller controller = Controller::construct();
        controller.startOperation();
    }

    /// 
    /// caption that appears on the dialog
    /// 
    /// the caption string
    protected ClassDescription defaultCaption()
    {
        return 'run';
    }

}

1. First, i had to pass the Id in the construct method and use this line in the method [Contract  contract =  controller.getDataContractObject(); to be able to pass the value to the service class, could i have done this in a better way? i don't think i should pass the value in construct or use getDataContract there as well.

Service class

class Service extends SysOperationServiceBase
{
    public void Demo(Contract _contract)
    {
       // logic
    }
}

2. How can i make it Async? what did i do wrong?

3. what is the difference between Async and ReliableAsync, which one should i choose?

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    Hi Junior AX,

    What is the business process you have to solve here? When someone will start a process which will show a dialog, then the user can cancel the process. Is it then still required to run your coding?

    What should be processed in your coding? What is 'class1' and 'method1'?

  • junior AX Profile Picture
    1,552 on at

    Hi Andre,

    The user clicks a button, then when the dialog opens, you can cancel or click ok.

    My code will run after ok is clicked.

    I don't want the dialog to wait for my code before it closes, that's why i want it to be async.

    class1 and method1, will export an entity and send a file to azure.

    For point 2 in my question: I put sleep(6000) in my service class and the dialog closed before the sleep ends. So i think it means that Async worked correctly right?  but maybe in debug things behave differently and i have to wait for my controller/service to finish?

    but I do still need help for point 1 and 3 please.

  • André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    Hi Junior AX,

    I wonder if you still need help here. I lost track of this question and just found it back. Do you still have the open questions on point 1 and 3?

  • junior AX Profile Picture
    1,552 on at

    Hi Andre,

    Yes i still need help with these two points if you can

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    When you say "their dialog must close right after their logic end", what's your defintion of "their logic"?

    Also, what do you mean by "super" in extensions? super() is used in inheritance, while you seems to be using CoC and you can't use super() there.

    By the way, Asynchronous execution mode is a different thing than a batch. The regular batch is SysOperationExecutionMode::ScheduledBatch. SysOperationExecutionMode::ReliableAsynchronous is also executed on a batch server - Asynchronous is not.

  • junior AX Profile Picture
    1,552 on at

    Hi Martin,

    What i mean by dialog must close after their logic ends, is that let's say when the dialog opens and u click ok their code posts a journals and the the dialog closes.

    I want the dialog to close right after the journal gets posted. I don't want their code to wait for my extra code i wrote in extension.

    And what i mean by after super is after next(). 

    As i said i'm not sure what i should do but it seems i need to do sth Asynchronous so that my code doesn't affect theirs. Right? 

    What's the difference between Async and reliable Async? 

    And what do u mean by sth runs on a batch server or not, what's the difference ?

     Also based on what i described do u think i need async or reliable async? 

  • Suggested answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    You seem to misunderstand how the framework works. If you have posting implemeted through SysOperation framework, the dialog is used for collecting input paramaters for posting. You fill in values, close the dialog and only then the posting logic can start. Therefore "I want the dialog to close right after the journal gets posted" makes no sense - the dialog is closed not just before the posting ends, but even before it starts.

    What is execution on batch server? When you want to execute something as a batch, it doesn't get executed in your session. It's saved to Batch* tables in database and a batch server reads data from there (taking into account recurrence and such things), load the parameters stored in database and execute the logic. If you didn't know that, you couldn't have made an informed decision about execution modes and you should review your decision.

  • junior AX Profile Picture
    1,552 on at

    Hi Martin,

    The dialog used for posting is not implemented through Sysoperation framework. It's a normal dialog, where some fields and grids gets filled. Then when i click ok the dialog freezes for maybe 2 seconds and when the journal gets posted the dialog closes.

    Now i want to add an extra logic using CoC but i don't want that logic to affect the time for psoting the journal and freezing the screen for an extra time.

    So in CoC i added 2 lines where i call the controller with Async (Sysoperation framework)

    What i do inside the service class of the SysOperationFramework is that i insert records in a log table that is used inside an entity. Afterward i check for a condition if that condition is met, i export the entity and send the file to azure.

    However for the records that got inserted without meeting the condition, i created a data project with a certain range and i enabled recurring job that gets executed every 5 minutes... Because alot of journals can get posted during 5 minutes.

    Now my question is:

    1. Using Async or Async reliable i'm still able to close the normal dialog for posting the journal without the logic using SysoperationFramework ends right?

    2. If AsyncReliable runs on a batch.. Then when using Async where it runs? Since based on point 1 if ur answer is yes it some how behaves like a batch because it also runs in the background

    3. Based on the logic i told you.. Should i use Async or reliable Async. I'm still confused about the difference between two and when should i use each one?

  • Verified answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    1) Yes, execution modes Asynchronous, ReliableAsynchronous and ScheduledBatch will execute your logic asynchronously, i.e. they won't block the calling thread. Only Synchronous does that.

    2) In a separate thread on the same server as the calling thread. As you see, running asynchronously and running as a batch isn't the same thing.

    3) I would likely use ReliableAsynchronous. When using Asynchronous and the sessions goes down for some reason, your code won't execute. It's fine in some cases, but probably not in this one. With ReliableAsynchronous, the data is already stored in batch tables and the process will execute at some point. Also, batch infrastructure allows you to track the execution if needed.

  • junior AX Profile Picture
    1,552 on at

    Hi Martin,

    1. Do you mean if the session goes down using Async. Then everything fails? but if i use reliable Async, then if the session goes down, it will still run? or it will run again automatically when the session goes back?

    2. Also what are some reasons for the session to go down?

    3. since Async doesn't run on a batch when i run it by code enternally.

    what If i make Async and let the the dialog pop out, there is an option to tick batch processing and i will be able to see a record in batch history. So does that mean that Async now runs on a batch just like reliable Async?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans