@@ -60,24 +60,7 @@ public override async Task<WorkflowExecutionStatus> ExecuteAsync(WorkflowExecuti
6060 {
6161 var mappings = JsonSerializer . Deserialize < List < ContactMappingDto > > ( ContactMappings ) ;
6262
63- string email = string . Empty ;
64- var mappedEmailGuid = Guid . Parse ( mappings . First ( p => p . ContactField == "email" ) . FormField . Id ) ;
65-
66- if ( context . Record . RecordFields . ContainsKey ( mappedEmailGuid ) == false )
67- {
68- // Get email when retrying workflow
69- var matchedField = context . Record . RecordFields . FirstOrDefault ( x => x . Value . FieldId == mappedEmailGuid ) ;
70- if ( matchedField . Value != null )
71- {
72- email = matchedField . Value . ValuesAsString ( ) ;
73- }
74- }
75- else
76- {
77- // Get email when executing workflow for the first time
78- email = context . Record . RecordFields [ mappedEmailGuid ]
79- . ValuesAsString ( ) ;
80- }
63+ string email = ReadMappingValue ( context . Record , mappings , "email" ) ;
8164
8265 if ( string . IsNullOrEmpty ( email ) )
8366 {
@@ -175,10 +158,27 @@ private ContactDto Build(Record record)
175158
176159 private string ReadMappingValue ( Record record , List < ContactMappingDto > mappings , string name )
177160 {
161+ string value = string . Empty ;
162+
178163 var mappingItem = mappings . FirstOrDefault ( p => p . ContactField == name ) ;
179164
180- return mappingItem != null
181- ? record . RecordFields [ Guid . Parse ( mappingItem . FormField . Id ) ] . ValuesAsString ( )
182- : string . Empty ;
165+ if ( mappingItem != null )
166+ {
167+ var key = Guid . Parse ( mappingItem . FormField . Id ) ;
168+ if ( ! record . RecordFields . ContainsKey ( key ) )
169+ {
170+ var matchedField = record . RecordFields . FirstOrDefault ( x => x . Value . FieldId == key ) ;
171+ if ( matchedField . Value != null )
172+ {
173+ value = matchedField . Value . ValuesAsString ( ) ;
174+ }
175+ }
176+ else
177+ {
178+ value = record . RecordFields [ key ] . ValuesAsString ( ) ;
179+ }
180+ }
181+
182+ return value ;
183183 }
184184}
0 commit comments