Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get options/parameters in workflow #5202

Closed
heitorgiacomini opened this issue Apr 8, 2024 · 2 comments
Closed

get options/parameters in workflow #5202

heitorgiacomini opened this issue Apr 8, 2024 · 2 comments

Comments

@heitorgiacomini
Copy link

I passed this parameter to my workflow on elsa

 var input = new Dictionary<string, object>
 {
     ["container"] = containerModel
 };
 var parametro = new StartWorkflowRuntimeParams();
 parametro.Input = input;
 var result = await _workflowRuntime.StartWorkflowAsync("CodeGenerationWorkflow", parametro);

now i want to get this value in my workflow

public class CodeGenerationWorkflow : WorkflowBase
    {
        protected override ValueTask BuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default)
        {
}
    }
Copy link

glime-ai bot commented Apr 8, 2024

To access the input parameter container that you passed to your workflow in Elsa, you can use the GetInput<T>() method within an activity's execution context. Here's an example of how you might do this within an activity in your CodeGenerationWorkflow:

public class CodeGenerationWorkflow : WorkflowBase
{
    protected override ValueTask BuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default)
    {
        builder
            .StartWith<CustomActivity>()
            .Then(/* ... other activities ... */);

        return base.BuildAsync(builder, cancellationToken);
    }
}

public class CustomActivity : Activity
{
    protected override IActivityExecutionResult OnExecute(ActivityExecutionContext context)
    {
        // Retrieve the 'container' input parameter
        var containerModel = context.GetInput<ContainerModel>("container");

        // Use the containerModel as needed within your activity
        // ...

        return Done();
    }
}

In this example, CustomActivity is an activity within your workflow where you want to access the container input. The OnExecute method is where you handle the execution of the activity, and you can call context.GetInput<ContainerModel>("container") to retrieve the input parameter.

Make sure to replace ContainerModel with the actual type of the container object you are passing to the workflow.

@heitorgiacomini
Copy link
Author

I would like to complain about the lack of documentation.
After much struggle i was able to get my objet only in Activity

protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
    {
        var containerModel = context.WorkflowInput.FirstOrDefault(x => x.Key == "container").Value;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant