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

Not able to save recordfields in a custom workflow #431

Closed
jkulker opened this issue Oct 20, 2020 · 6 comments
Closed

Not able to save recordfields in a custom workflow #431

jkulker opened this issue Oct 20, 2020 · 6 comments

Comments

@jkulker
Copy link

jkulker commented Oct 20, 2020

I created a customwork workflow that is adding values to specific fields. The code hits all the code but not saved in the database.

public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
            var correctCount = 0;
            var questionIsTrue = "true";
            foreach (var recordField in record.RecordFields.Values)
            {
                if (recordField.HasValue() && recordField.Values.Any(x => questionIsTrue.Contains(x.ToString())))
                {
                        correctCount++;
                }

                if (recordField.Alias == "passed")
                {
                    recordField.Values.Add(correctCount >= this.correctAnswersNeeded);
                }

                if (recordField.Alias == "correctAnswers")
                {
                    recordField.Values.Add(correctCount);
                }
                record.
            }

            // HttpContext.Current.Response.Redirect("resultaat");
            return WorkflowExecutionStatus.Completed;
        }

Umbraco: 8.8
Forms: 8.5.3

Bug summary

Impossible to save data in recordfield


This item has been added to our backlog AB#9369

@jordanc44
Copy link

I'm also having the same issue. I have a workflow that runs on submit that changes the value of a hidden field. This worked fine on forms version 8.3 but now none of my changes are saved after upgrading to 8.5.3.

My code:

 public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {

            // Iterate through the form fields
            foreach (RecordField rf in record.RecordFields.Values)
            {
                // Find the hidden value
                if(rf.Alias.ToLower() == "ordernumber")
                {
                    // set the value to the current order number
                    rf.Values.Clear();
                    rf.Values = new List<object> { _orderService.GetOrderNumber() };
                }
            }
            return WorkflowExecutionStatus.Completed;
        }

@nul800sebastiaan
Copy link
Member

Thanks, I can confirm this worked in Forms 8.3.2 and stopped working in v8.4. We'll need to have a look.

The full code I used:

using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Forms.Core;
using Umbraco.Forms.Core.Enums;
using Umbraco.Forms.Core.Persistence.Dtos;

namespace MyNamespace
{
  public class CustomWorkflow : WorkflowType
   {
      public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
      {
          foreach (var rf in record.RecordFields.Values.Where(rf => rf.Alias.ToLower() == "ordernumber"))
          {
              // set the value to the current order number
              rf.Values.Clear();
              rf.Values = new List<object> { "overruled" };
          }


          return WorkflowExecutionStatus.Completed;
      }

      public override List<Exception> ValidateSettings()
      {
          return new List<Exception>();
      }
   }
}

I have a field of type short answer with the alias of ordernumber and it doesn't matter if I try to store forms in the database or not, neither of them accept the value being changed.

@nul800sebastiaan nul800sebastiaan added project/workflows state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks status/regression labels Nov 10, 2020
@warrenbuckley
Copy link

Thanks for the example @nul800sebastiaan
I can reproduce and now playing the lovely game of spot the difference to see what's happened and is causing this issue

https://github.com/umbraco/Forms/compare/v8.3.2...v8.4.0

@warrenbuckley
Copy link

warrenbuckley commented Nov 17, 2020

As I am running out of time before I hit holiday for a few days, but debugging and stepping through the problem seems to lies in the changes in the workflow service. Linking this here for reference when I come back next week

WorkflowService.cs

@miackers
Copy link

miackers commented Dec 3, 2020

Hi @warrenbuckley, any update on this?

I am having the same issue running Umbraco Forms v8.5.5, and tried v8.60 now as well.

Mine is slightly different - I am using code similar to #186 (comment) , biggest difference being I am calling
record.Created = DateTime.Now; _recordStorage.UpdateRecord(record, e.Form);
as well.

Last known version where I know this worked was in Umbraco Forms v8.3.2

Environment details:

  • Umbraco v8.6.5
  • Umbraco Forms v8.5.5 & v8.60
  • StoreUmbracoFormsInDb = False (Using UmbracoFileSystemProviders.Azure.Form v2.0.0 for storage)
  • Have load balanced environment, but my local/dev box is set to MasterServer, so I doubt that matters

If you need any more information, let me know.

@warrenbuckley
Copy link

This has been fixed and will be in the next version 8.6.1

@umbrabot umbrabot removed the state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks label Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants