umbraco/Umbraco.Forms.Issues

[13.1.2] When using RecordService.ApproveAsync() from a Workflow the Record is Approved Twice

Closed this issue · 1 comments

When using RecordService.ApproveAsync() from a custom workflow the Record is approved twice and any workflows triggered by On Approve are also executed twice. Oddly, from the same custom workflow using RecordService.RejectAsync() does not reject twice. The Form has Enable post moderation set to ON

According to the log entries, the Form Entry Approved happens twice, about 1-second apart, with the identical set of log information except the ThreadId is sometimes different.

Reproduction

Umbraco Cloud
Umbraco CMS 13.3.2
Umbraco Forms 13.1.2
Custom Workflow
Form has Enable post moderation set to ON
Form DisableDefaultWorkflow set to True

Configuration

    "Forms": {
      "FormDesign": {
        "DisableDefaultWorkflow": true
      }

Custom Workflow

        public override async Task<WorkflowExecutionStatus> ExecuteAsync(WorkflowExecutionContext context)
        {
            // Assume this is a valid email, set the redirect to a 'THANK YOU' page
            _httpContextAccessor.HttpContext.Items[Constants.ItemKeys.RedirectAfterFormSubmitUrl] = "/thank-you";

            string email = context.Record.ValueAsString("email");

            // check if the email is a disposable email address and redirect to a 'NO thank you' page if matched
           // or something else that returns True
            if (_disposableEmailService.IsDisposableEmail(email))
            {
                // This is a spam email, redirect to a 'NO thank you' page, return early
                _httpContextAccessor.HttpContext.Items[Constants.ItemKeys.RedirectAfterFormSubmitUrl] = "/no-thank-you";

                // set the Form status to 'Rejected' and return
                _recordService.RejectAsync(context.Record, context.Form).Wait();

                return await Task.FromResult(WorkflowExecutionStatus.Completed);
            }
            else
            {
                // if we made it this far , the email is valid, Approve the record
                _recordService.ApproveAsync(context.Record, context.Form).Wait();
            }
            return await Task.FromResult(WorkflowExecutionStatus.Completed);
        }

Steps to reproduce

Attach the custom workflow to Form's On Submit trigger and also add any other workflow to the On Approve trigger. We are using the Send Email workflow here.

Expected result

The On Approve workflow is not run when the form is rejected (that works as expected) and is run one time when the form is approved.

Actual result

When approved, the On Approve workflow is run twice, also logged twice. See log entries below with identical data except for the timestamp.
image
image

The Workflow Audit shows the custom workflow run once and the Send Email workflow run twice

image

Thanks for reporting @paulsterling - we have found a bug here and resolved for the next releases.