elsa-workflows / elsa-workflows/elsa-core

workflowRunner.RunAsync is not retuning Result when trying to resume workflow.

Open
#5,072 2 comments 0 reactions 0 assignees View on GitHub
elsa 3 triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

I am trying to resume workflow and get result of Result variable on it.

using below code to resume workflow for specific InstanceId,BookmarkId
```
var options = new WorkflowInstanceFilter
{
Id = InstanceId,
};
var workflowInstance = await _workflowInstanceStore.FindAsync(options);
var workflowState = workflowInstance.WorkflowState;
var workflow = await _workflowBuilderFactory.CreateBuilder().BuildWorkflowAsync();
var bookmark = workflowInstance.WorkflowState.Bookmarks;
var runoption = new RunWorkflowOptions();

foreach (var item in bookmark)
{
if (((Elsa.Workflows.Runtime.Bookmarks.EventBookmarkPayload)item.Payload).EventName == respose)
{
runoption.BookmarkId = item.Id;
break;
}
}
var result= await _workflowRunner.RunAsync(workflow,workflowState,runoption);
var res = **result.Result**;
```
My Workflow is look like:
```
public class ApprovalWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder builder)
{
var approvedVariable = builder.WithVariable();
var sum = builder.WithVariable>().WithMemoryStorage();

var FetchPrograms = new FetchPrograms(sum);
builder.Root = new Sequence
{
Activities =
{
new Fork
{
JoinMode = ForkJoinMode.WaitAll,
Branches =
{
new Sequence
{
Activities =
{
new Fork
{
JoinMode = ForkJoinMode.WaitAny,
Branches =
{
// Approve
new Sequence
{
Activities =
{
new Event("Approve"),
new SetVariable
{
Variable = approvedVariable,
Value = new(true)
}
}
},

// Reject
new Sequence
{
Activities =
{
new Event("Reject"),
new SetVariable
{
Variable = approvedVariable,
Value = new(false)
}
}
}
}
}
}
},
}
},

new WriteLine(context => $"Approved: {approvedVariable.Get(context)}"),
new If(context => approvedVariable.Get(context))
{
Then = new Sequence
{
Activities =
{
new WriteLine("If condition started!"),
FetchPrograms,
new WriteLine(context => $"value : {sum.Get(context).First().ProgramCode }"),
new SetVariable
{
Variable = Result,
Value = new (context => sum.Get(context).First()),

}
}
},
Else =
new WriteHttpResponse
{
Content = new("Request rejected!"),
}
}
}

};

}
}
```
In Sum, Getting result from CodeActivity but same i not able to get it . I didn't find relevant sample example which will resume workflow and return result. Additionally, Flow is resume the request received the response but in response Result is null,

Contributor guide

Open the contributing guide

Research direction

Start with the resume path using workflowRunner.RunAsync, WorkflowInstanceFilter, RunWorkflowOptions, and the workflowState.Bookmarks shown in the report. Trace how the WorkflowBase variable is set after the Event bookmark resumes, and verify that a resumed ApprovalWorkflow exposes the assigned value through the returned result.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.