Skip to content

Commit 66e2ec4

Browse files
authored
Merge pull request #109 from EJTRES/bugfix/v13/activecampaign-retry-workflow
Fix ActiveCampaign workflow retry
2 parents e448be2 + 7ff9880 commit 66e2ec4

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/Umbraco.Forms.Integrations.Crm.ActiveCampaign/ActiveCampaignContactsWorkflow.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,30 @@ public override async Task<WorkflowExecutionStatus> ExecuteAsync(WorkflowExecuti
6060
{
6161
var mappings = JsonSerializer.Deserialize<List<ContactMappingDto>>(ContactMappings);
6262

63-
var email = context.Record.RecordFields[Guid.Parse(mappings.First(p => p.ContactField == "email").FormField.Id)]
64-
.ValuesAsString();
63+
string email = string.Empty;
64+
var mappedEmailGuid = Guid.Parse(mappings.First(p => p.ContactField == "email").FormField.Id);
6565

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+
}
81+
82+
if (string.IsNullOrEmpty(email))
83+
{
84+
_logger.LogWarning("Email not set for the record!");
85+
return WorkflowExecutionStatus.Failed;
86+
}
6687
// Check if contact exists.
6788
var contacts = await _contactService.Get(email);
6889

@@ -160,4 +181,4 @@ private string ReadMappingValue(Record record, List<ContactMappingDto> mappings,
160181
? record.RecordFields[Guid.Parse(mappingItem.FormField.Id)].ValuesAsString()
161182
: string.Empty;
162183
}
163-
}
184+
}

0 commit comments

Comments
 (0)