@@ -59,8 +59,14 @@ public override async Task<WorkflowExecutionStatus> ExecuteAsync(WorkflowExecuti
5959 {
6060 var mappings = JsonSerializer . Deserialize < List < ContactMappingDto > > ( ContactMappings ) ;
6161
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+
6470
6571 // Check if contact exists.
6672 var contacts = await _contactService . Get ( email ) ;
@@ -153,11 +159,28 @@ private ContactDto Build(Record record)
153159
154160 private string ReadMappingValue ( Record record , List < ContactMappingDto > mappings , string name )
155161 {
162+ string value = string . Empty ;
163+
156164 var mappingItem = mappings . FirstOrDefault ( p => p . ContactField == name ) ;
157165
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 ;
161184 }
162185 }
163186}
0 commit comments