@@ -59,8 +59,14 @@ public override async Task<WorkflowExecutionStatus> ExecuteAsync(WorkflowExecuti
59
59
{
60
60
var mappings = JsonSerializer . Deserialize < List < ContactMappingDto > > ( ContactMappings ) ;
61
61
62
- var email = context . Record . RecordFields [ Guid . Parse ( mappings . First ( p => p . ContactField == "email" ) . FormField . Id ) ]
63
- . ValuesAsString ( ) ;
62
+ string email = ReadMappingValue ( context . Record , mappings , "email" ) ;
63
+
64
+ if ( string . IsNullOrEmpty ( email ) )
65
+ {
66
+ _logger . LogWarning ( "Email not set for the record!" ) ;
67
+ return WorkflowExecutionStatus . Failed ;
68
+ }
69
+
64
70
65
71
// Check if contact exists.
66
72
var contacts = await _contactService . Get ( email ) ;
@@ -153,11 +159,28 @@ private ContactDto Build(Record record)
153
159
154
160
private string ReadMappingValue ( Record record , List < ContactMappingDto > mappings , string name )
155
161
{
162
+ string value = string . Empty ;
163
+
156
164
var mappingItem = mappings . FirstOrDefault ( p => p . ContactField == name ) ;
157
165
158
- return mappingItem != null
159
- ? record . RecordFields [ Guid . Parse ( mappingItem . FormField . Id ) ] . ValuesAsString ( )
160
- : string . Empty ;
166
+ if ( mappingItem != null )
167
+ {
168
+ var key = Guid . Parse ( mappingItem . FormField . Id ) ;
169
+ if ( ! record . RecordFields . ContainsKey ( key ) )
170
+ {
171
+ var matchedField = record . RecordFields . FirstOrDefault ( x => x . Value . FieldId == key ) ;
172
+ if ( matchedField . Value != null )
173
+ {
174
+ value = matchedField . Value . ValuesAsString ( ) ;
175
+ }
176
+ }
177
+ else
178
+ {
179
+ value = record . RecordFields [ key ] . ValuesAsString ( ) ;
180
+ }
181
+ }
182
+
183
+ return value ;
161
184
}
162
185
}
163
186
}
0 commit comments