Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kenneth123 2 posts 92 karma points
    Nov 16, 2016 @ 12:18
    Kenneth123
    0

    Trigger "On approve" workflows from "On submit" workflow

    I have the following code in a custom WorkflowType for changing record state from Submitted to Approved.

    FormStorage fs = new FormStorage();
    Form f = fs.GetForm(record.Form);
    RecordStorage rs = new RecordStorage();
    
    record.State = FormState.Approved;
    
    rs.UpdateRecord(record, f);
    
    fs.Dispose();
    rs.Dispose();
    

    This works as expected - however it does not trigger the defined workflows for the "On approve"-event. How do I solve this problem in Umbraco Forms v4.3.3? I am able to trigger the workflows manually from the Umbraco back-end, but not from my WorkflowType-code.

  • Kenneth123 2 posts 92 karma points
    Nov 18, 2016 @ 14:57
    Kenneth123
    100

    I solved the issue. In order to change a record's state to approved AND trigger the "On approve"-workflows the RecordService must be used:

    FormStorage fs = new FormStorage();
    Form f = fs.GetForm(record.Form);
    
    var rs = new RecordService();
    rs.Approve(record, f);
    
    fs.Dispose();
    

    The RecordService class can be found in the namespace: "Umbraco.Forms.Web.Services"

  • Romeo Cadaoas 33 posts 110 karma points
    Aug 01, 2017 @ 08:03
    Romeo Cadaoas
    0

    Hi. I tried this but my "On approve" workflow is not getting executed. Anybody else getting this issue?

    This is my code:

    var task = new System.Threading.Tasks.Task(() =>
    {
        if (record != null)
        {
            using (var formStorage = new Umbraco.Forms.Data.Storage.FormStorage())
            {
                Umbraco.Forms.Core.Form form = formStorage.GetForm(record.Form);
    
                if (record.RecordFields.Any(x => x.Value.Field.Caption == "Payment Reference"))
                {
                    record.GetRecordField("Payment Reference").Values.Clear();
                    record.GetRecordField("Payment Reference").Values = new List<object> { tranid };
                }
                var recordService = new Umbraco.Forms.Web.Services.RecordService();
                recordService.Approve(record, form);
    
            }
    
        }
    });
    task.Start();
    
  • Mark 122 posts 255 karma points
    Oct 01, 2017 @ 13:13
    Mark
    0

    @Romeo, I have had the same issue..

    recordService.Submit(record, form); 
    

    Has worked fine for me, workflows are triggered correctly, however, calling .Approve() seems to not trigger anything. The status appears to get updated, but no workflows for OnApproved are called.

    Did you have any luck getting around this?

    I am going to write my own function to replace the workflow if I can't get this working, as a workflow is 100% necessary, more of a nicety for what I am doing, but it would be great to know .Approve does really work if I need it later..

    Cheers,

    Mark

Please Sign in or register to post replies

Write your reply to:

Draft