-
-
Save Nicholas-Westby/8ff266eb9f9f0bfd5908d7022d730340 to your computer and use it in GitHub Desktop.
Formulate function to set an email recipient based on the current page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Sets the "Dynamic Email Recipient" field based on the current page. | |
/// </summary> | |
/// <param name="context"> | |
/// The form submission context. | |
/// </param> | |
private static void SetEmailByPage(FormSubmissionContext context) | |
{ | |
// Find the "Dynamic Email Recipient" field (exit early if not found). | |
var field = context.Form.Fields | |
.Where(x => x.Category == "Dynamic Email Recipient") | |
.FirstOrDefault(); | |
if (field == null) | |
{ | |
return; | |
} | |
// Get the recipient email address from the current page. | |
var recipient = context.CurrentPage.GetPropertyValue<string>("emailRecipient"); | |
// Copy the field data into a new list. | |
var newData = new List<FieldSubmission>(context.Data); | |
// Set field data to the email address. | |
MergeFieldData(newData, field, recipient); | |
// Ensure the modified field data gets used. | |
context.Data = newData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment