Copied to clipboard

Flag this post as spam?

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


  • Jan Vanuytrecht 32 posts 80 karma points
    Jul 06, 2015 @ 13:02
    Jan Vanuytrecht
    0

    Get node (id) of prevalue source item in workflowtype

    Hi,

    I've created a custom workflow type with Countour v 3.0.23.

    This purpose is to send the form data to another data store. (in this case, a queue). I hook my workflowtype in on the "submitted" event".

    One field is a checkboxlist with a prevalue source of Umbraco documents as prevalue type.

    In the workflow I have a fieldmapper control to map this property; but I don't think this is really relevant.

    No my question is how that I can easily access the node(s) that were chosen or it's Id's. Because now all I get is the labels from the saved record.

    I need this because there is data stored on the node that I want to pass to the other data store. The best scenario would be the node, otherwise the nodeId to get the node myself from the cache.

    Any help is much appreciated.

    Tnx!

  • Comment author was deleted

    Jul 06, 2015 @ 13:06

    How are you getting the values from the record ? Mind sharing a code snippet

  • Jan Vanuytrecht 32 posts 80 karma points
    Jul 06, 2015 @ 13:25
    Jan Vanuytrecht
    0

    Yes, srry that might help :))

    Fields property on workflowtype:

    [Setting("Fields", description = "Map the needed fields",
                control = "Umbraco.Forms.Core.FieldSetting.FieldMapper")]
            public string Fields { get; set; }
    

    Code to get a list of the mapped values:

    var formFields = Fields.Split(';');
            var values = new Dictionary<string, object>();
    
            if (formFields.Length > 0)
            {
                foreach (var formField in formFields)
                {
                    var vals = formField.Split(',');
                    if (vals.Length == 3)
                    {
                        var alias = vals[0];                        
                        var value = !string.IsNullOrEmpty(vals[2]) ? vals[2] : string.Join(";", record.RecordFields[new Guid(vals[1])].Values.ToArray());
    
                        values.Add(alias, value);
                    }
                }
            }
            else
            {
                foreach (var rf in record.RecordFields.Values)
                {                    
                    values.Add(rf.Field.Caption.Replace(" ", ""),
                        string.Join(";", rf.Values.ToArray()));
                }
            }
    
  • Jan Vanuytrecht 32 posts 80 karma points
    Jul 06, 2015 @ 13:29
    Jan Vanuytrecht
    0

    That mapping code comes from the overridden " WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)" method ofcourse

  • Comment author was deleted

    Jul 06, 2015 @ 14:19

    You could fetch it by node id but this is the least performant way, looking into a way to just have the id available in the workflow

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); var contentNode = umbracoHelper.TypedContentSingleAtXPath(String.Format("//* [@isDoc and @nodeName = '{0}']", name);

    You should also be able to fetch the prevalue source from within the workflow, something like

    var field = e.Form.AllFields.Where(x => x.PreValues.Any() && x.Id = new Guid("")).Single(); var prevalueId = field.PreValues.Where(x => x.Value == "value");

  • Jan Vanuytrecht 32 posts 80 karma points
    Jul 08, 2015 @ 09:13
    Jan Vanuytrecht
    0

    Hi Tim,

    Thanks for your reply!

    The problem is that in the workflow only the fields' prevaluesource is known.

    The prevalues list is null when I hook my custom workflow into the "Ater submit" event in the Form's workflow.

    In the View of that field the Prevalues are present.

  • Comment author was deleted

    Jul 09, 2015 @ 09:12

    Ok will setup a test site to see what is needed to get the ids, will report back later today

  • Comment author was deleted

    Jul 09, 2015 @ 12:54

    Hey,

    If you add the following snippet to your workflow it should populate the prevalues. I'll look into adding this at the correct place in the core but for know you can use this as a workaround

     foreach(var field in e.Form.AllFields)
            {
                if(field.PreValueSource != null)
                    field.PreValueSource.Type.LoadSettings(field.PreValueSource);
    
                field.PreValues = field.PreValueSource.Type.GetPreValues(field);
            }
    
  • Comment author was deleted

    Jul 09, 2015 @ 12:55

    of course once the prevalues are populated you can filter them by value to get the correct id...

Please Sign in or register to post replies

Write your reply to:

Draft