Copied to clipboard

Flag this post as spam?

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


  • Andrew 32 posts 52 karma points
    Feb 16, 2010 @ 22:37
    Andrew
    0

    Access Field Value in Workflow

    This is probably really simple, but how do I access a specific field value in a custom workflow?  I see that I can use record.RecordFields.Values to get all of the fields, but I want to get a specific field.  Thanks.

  • Harald Ulriksen 207 posts 249 karma points
    Feb 17, 2010 @ 11:12
    Harald Ulriksen
    0

    If you know the Guid Key of the record field you can use the Guid or field caption. As the Guid changes when I recreate the same form on another Umbraco installation I go for the caption, however changing the caption will then break your code so make sure to use dictionary to display caption name (see video on multi language contour).

    An extension method can come in handy.

            public static RecordField GetByLabel(this Record record, string labelName)
            {
                return record.RecordFields.Values.Where(value => value.Field.Caption == labelName).FirstOrDefault();
     
            }

    I think I miss the alias property (or I'm just doing something wrong).
     

     

  • Andrew 32 posts 52 karma points
    Feb 17, 2010 @ 14:27
    Andrew
    0

    Hi Harald, Thanks for your help.  I don't have the .Where function.  Is there an assembly that I need to include? 

  • Harald Ulriksen 207 posts 249 karma points
    Feb 17, 2010 @ 18:40
    Harald Ulriksen
    1

    Oh, that's me using Linq, it's in .net framework 3.5 which ships with Visual Studio 2008.

    You can do the same just looping through the values in the recordfields, something in the line of

    foreach(RecordField rf in record.RecordFields.Values){
        if (rf.Field.Caption == labelName)
           return rf
    }
    return null;

Please Sign in or register to post replies

Write your reply to:

Draft