Skip to content

Instantly share code, notes, and snippets.

@Nicholas-Westby
Created May 12, 2018 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicholas-Westby/8ff266eb9f9f0bfd5908d7022d730340 to your computer and use it in GitHub Desktop.
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.
/// <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