question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get user actions dynamically

See original GitHub issue

Hi! I need to get user actions dynamically, I have already seen an example Sample12 and there I can change code like this and get actions:

using System;
using System.Linq;
using System.Threading.Tasks;
using Elsa.Activities.Console.Extensions;
using Elsa.Activities.UserTask.Activities;
using Elsa.Extensions;
using Elsa.Models;
using Elsa.Services;
using Elsa.Services.Extensions;
using Microsoft.Extensions.DependencyInjection;

namespace Sample12
{
    /// <summary>
    /// Demonstrates workflow correlation & user tasks.
    /// </summary>
    public static class Program
    {
        public static async Task Main(string[] args)
        {
            var services = BuildServices();
            var registry = services.GetService<IWorkflowRegistry>();
            var workflowDefinition = await registry.GetWorkflowDefinitionAsync<UserTaskWorkflow>();
            var invoker = services.GetRequiredService<IWorkflowInvoker>();

            // Start the workflow.
            var correlationId = Guid.NewGuid().ToString("N");
            var executionContext = await invoker.StartAsync(workflowDefinition, correlationId: correlationId);

            do
            {
                var activity = (UserTask) executionContext.CurrentActivity;
                // Workflow is now halted on the user task activity. Ask user for input:
                Console.WriteLine($"What action will you take? Choose one of: {string.Join(", ", activity.Actions)}");
                var userAction = Console.ReadLine();

                // Resume the workflow with the received stimulus.
                var triggeredExecutionContexts = await invoker.TriggerAsync(nameof(UserTask), new Variables { ["UserAction"] = new Variable(userAction)}, correlationId);
                executionContext = triggeredExecutionContexts.First();

            } while (executionContext.Workflow.IsExecuting());
        }

        private static IServiceProvider BuildServices()
        {
            return new ServiceCollection()
                .AddElsa()
                .AddConsoleActivities()
                .AddWorkflow<UserTaskWorkflow>()
                .BuildServiceProvider();
        }
    }
}

But in my application workflow is already started and if try to construct WorkflowExecutionContext like this

var workflowFactory = services.GetRequiredService<IWorkflowFactory>();
var workflow = workflowFactory.CreateWorkflow(workflowDefinition);
var executionContext = new WorkflowExecutionContext(workflow, services.GetRequiredService<IClock>(), services);
var userTask = (UserTask) executionContext.CurrentActivity;

My variable userTask is null.

Briefly, I need something like GetOpenUserActions in WorkflowCore.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
uppercuutcommented, Sep 29, 2021

For Anyone who ask about this , after reading the great documentation UserTask is just a class the inherits from activity .

it has one more virtual method which called OnCanExecute which retruns a bool if true it will go as a normal activity if not it will just terminate the execution .

its also had ActivityInput called action which takes the actions as string[] .

https://elsa-workflows.github.io/elsa-core/docs/next/guides/guides-blocking-activities

this tutorial is more than enough for the user task example.

finaly, thanks for this awesome library

0reactions
sfmskywalkercommented, Sep 27, 2021

I’m afraid not as of yet. Shifting priorities and all that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Get event from dynamically added button in UserControl
I want the event to be raised in the Form in which i am adding the UserControl . Please if anyone could suggest...
Read more >
Use Dynamic Actions to Show the Right Actions to the User at ...
Dynamically show actions to your users using action visibility in Lightning Experience. Important things to note about dynamic actions: Dynamic ...
Read more >
Dynamically creating JavaScript elements with event ...
This tutorial explores the concepts of events, event listeners, and dynamically creating new JavaScript elements by using document.
Read more >
Dynamically generated Django admin actions
Django's admin actions are a useful way of applying a process to a set of records. Django by default has only “delete selected...
Read more >
Salesforce Dynamic Actions: Overview & Deep Dive Tutorial
Dynamic Actions will enable you to create uncluttered, intuitive and responsive pages that display only the actions your users need to see ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found