$currentSession can’t be retrieved on asynchronous Microflow?

Dears, Using Widgets:"Process Queus" or "Queue", could you tell me how to pass (or set to $currentSession,$currentUser) $currentSession,$currentUser on Microflow which is executed asynchronously? Reagards.
3 answers

Microflows in the process queue run in the system context and do not have a user specific context. Thus you cannot retrieve a session. However, if you need specific user information in that microflow, you can associate Account to QueuedAction, and retrieve Account in the microflow that is executed in the queue.


I will describe the detailed contents that I solved myself.
As Mr.Thorsten Biehl said, asynchronous Queues process run on the system, so there is no user session or information ($currentUser/$currentSession).
To that end, I thought of a way to pass user sessions and information to an asynchronous Queue process in advance using Java.

I customized the Queue handler (javasource/queue/usecases/QueueHandler.java).

1) Add Property:SessionId and UserName to Entity:Job of Domain Model of Queue.
2) After creating an asynchronous Queue process, set the session ID and user name ($currentSession/SessionId, $currentUser/Name) in Entity:Job.
3) Add as follows in the handler of asynchronous Queue process.
    String sessionId = job.getSessionId();
    String userName = job.getUserName();
    IUser user = Core.getUser(context, userName);
    ISession session = Core.initializeSession(user, sessionId);

    HashMap<String, Object> jobInput = microflowRepository.getJobInput(jobObject, microflowName);

    jobInput.put("CSession", session.getMendixObject());
    jobInput.put("CUser", user.getMendixObject());
    jobRepository.executeJob(context, microflowName, true, jobInput);

4) These sessions and user information can be passed to the asynchronous Queue microflow.
For example,  we can set a context such as TeamCenter with this asynchronous Queue.


I thought about another method.

This is a method to start an asynchronous job in the main session without starting it in the system.



QueueHandler (IContext context_u, ILogNode logger,
    this.context_u = context_u;

    //context = queueRepository.getSystemContext();     // ← convert context from user context
    context = context_u;