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.
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).
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.
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.
I think I miss the alias property (or I'm just doing something wrong).
Hi Harald, Thanks for your help. I don't have the .Where function. Is there an assembly that I need to include?
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;
is working on a reply...