@@ -60,24 +60,7 @@ public override async Task<WorkflowExecutionStatus> ExecuteAsync(WorkflowExecuti
60
60
{
61
61
var mappings = JsonSerializer . Deserialize < List < ContactMappingDto > > ( ContactMappings ) ;
62
62
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" ) ;
81
64
82
65
if ( string . IsNullOrEmpty ( email ) )
83
66
{
@@ -175,10 +158,27 @@ private ContactDto Build(Record record)
175
158
176
159
private string ReadMappingValue ( Record record , List < ContactMappingDto > mappings , string name )
177
160
{
161
+ string value = string . Empty ;
162
+
178
163
var mappingItem = mappings . FirstOrDefault ( p => p . ContactField == name ) ;
179
164
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 ;
183
183
}
184
184
}
0 commit comments