Umbraco Forms - Add record field from workflow

Hi All,

I’m sure this is easy, but for the life of me I can’t figure it out, in my workflow I need to add a custom field which contains the transactionid, which is generated during the workflow execution.

Using the code below I am adding the field:

context.Record.RecordFields.Add(Guid.NewGuid(), new RecordField(new Field
{
    Alias = "transactionId",
    FieldTypeId = Guid.Parse("DA206CAE-1C52-434E-B21A-4A7C198AF877"),
    Caption = "Transaction Id",
    Id = Guid.NewGuid(),
    Values = new List<object>
    {
        updateStartResponse?.TransactionReference ?? string.Empty
    }
}));

However this is not being persisted to the database.

If I add the below line:
_recordStorage.UpdateRecord(context.Record, context.Form);

I then get the following error:

The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_UFRecordFields_UFRecords_Id\"

Hi @AaronSadlerUK

What is the purpose for the field?

Where is this code

context.Record.RecordFields.Add(Guid.NewGuid(), new RecordField(new Field
{
    Alias = "transactionId",
    FieldTypeId = Guid.Parse("DA206CAE-1C52-434E-B21A-4A7C198AF877"),
    Caption = "Transaction Id",
    Id = Guid.NewGuid(),
    Values = new List<object>
    {
        updateStartResponse?.TransactionReference ?? string.Empty
    }
}));

After talking to their api a transactionid is returned, I need to add this into the umbraco forms record / entry.

The code above is in the custom workflow

What if you created a hiddenfield on the form and set the value in the workflow?

I have used this field to map the field in the workflow


  [Setting("Fields", Description = "Map the needed fields  - These fields are required to map:  {insert required field} ", View = "FieldMapper", SupportsPlaceholders = true, DisplayOrder = 40)]
  public virtual string Fields { get; set; } = string.Empty;

Yeah I was just wondering why you’d need to dynamically create a field, the form could already contain a field to hold this value?

I was trying to make sure the editor could not miss the field off, or configure it incorrectly.

I have gone another route now with a custom table to store the information

1 Like