danielgerlag / danielgerlag/workflow-core

Workflow step requires approval; rejection starts the workflow over

Open
#993 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
5.9k
Forks
1.3k
Avg merge
1d 1h
Merged PRs (30d)
5

Description

Hello, Daniel,

In Issue #330 you said you could provide an example of a workflow with approval/rejection given more detail. Could you please provide an idea for the following?

The workflow prompts a user to fill out some data for a project. The workflow waits for the manager's approval and retrieves the answer via an event. The workflow then provides a branching structure based on the manager's response. If the manager has approved the work the workflow follows one branch forward to the next workflow step. If the manager has rejected the work, the workflow starts over at the prior step prompting the user to correct the data and resubmit it for approval.

How can I accomplish this? Thanks in advance!

This is my attempt:
```
public void Build(IWorkflowBuilder builder)
{
var userNotificationProcess = builder
.StartWith(context => ExecutionResult.Next())
.Then()
.Input(step => step.UserName, data => "ProjectOwner@Company.com");

var approvalBranch = builder.CreateBranch()
.StartWith()
.Input(step => step.Message, data => "The plan is approved")
.Then()
.Input(step => step.Message, data => "Moving to next step")
.Then()
.Input(step => step.UserName, data => "NextUser@Company.com");

var rejectionBranch = builder.CreateBranch()
.StartWith()
.Input(step => step.Message, data => "The plan is rejected")
.Then()
.Input(step => step.Message, data => "Starting plan over")
.Then(userNotificationProcess);

userNotificationProcess
.WaitFor("Approval_Decision", (data, context) => context.Workflow.Id, date => DateTime.Now.ToUniversalTime())
.Output(data => data.Value, step => step.EventData)
.Decide(data => data.Value)
.Branch("yes", approvalBranch)
.Branch("no", rejectionBranch);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.