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

Using iteration Item in IF #599

Open
andreasfrei opened this issue Jul 11, 2020 · 3 comments
Open

Using iteration Item in IF #599

andreasfrei opened this issue Jul 11, 2020 · 3 comments

Comments

@andreasfrei
Copy link

Hello
I would like to use from a ForEach statement the iteration item in the IF.

Something like this:

        steps.ForEach(data => data.WorkflowEvent.Actions)
                .Do(ac => ac
                    .StartWith<ExecuteAction>().Input((step, data, context) => step.inConsumerAction = (ConsumerAction)context.Item)
                    .If(ac => ac.ActionType == "ABC")
                        .Do(then => then
                            .StartWith<PrintMessage>()
                            .Input(step => step.Message, data => "Value is less than 3")
                            )
                    )

With "context.Item" i can get to the iteration item, but not in the IF statement. Is this somehow possible?

@danielgerlag
Copy link
Owner

You should be able to include a second parameter on the lambda for the context object

Something like

.Input(step => step.Message, (data, context) => "Value is less than " + context.Item)

@dviry
Copy link
Contributor

dviry commented Jul 11, 2020

I think he means he has no access to the Context.Item from the .If condition - having the same problem myself ;)

Just found this #338...

@andreasfrei
Copy link
Author

It was not so clear from my side. I would need access to the context.Item in the If condition.

in the below statements I can use the "ac" as an iteration element. Making a separate Step with "ExecutionAction" I could also not finde a solution to use the executionAction.Output. Is there any way to access the iteration step variable in an If. I need to decide for the further flow?

Thanks, and good work with workflowcore!

steps.ForEach(data => data.WorkflowEvent.Actions)
.Do(ac => ac
.StartWith().Input((step, data, context) => step.inConsumerAction = (ConsumerAction)context.Item)
.If(ac => ac.ActionType == "ABC")
.Do(then => then
.StartWith()
.Input(step => step.Message, data => "Value is less than 3")
)
)

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

3 participants