I have created a Sitecore 9 form with a custom button as shown below:
On click of this "Subscribe" button I am saving the email of the contact in Xdb (Experience profile).
Also, I have created a custom tab ("Consent") and field ("Newsletter Consent") in Experience profile which will be visible to all users with the help of the following post
https://community.sitecore.net/technical_blogs/b/getting_to_know_sitecore/posts/using-custom-contact-data-part-1-experience-profile
:
Now my question is, how do I add the value to this custom field. For now, all those users who enter their email and click subscribe, this "Newsletter consent" value should be true and should be visible against it's label in experience profile. I am unable to set it's value like I have done for email on custom button click.
private static void SetEmail(string email, Contact contact, IXdbContext client)
{
if (string.IsNullOrEmpty(email))
{
return;
}
EmailAddressList emailFacet = contact.Emails();
if (emailFacet == null)
{
emailFacet = new EmailAddressList(new EmailAddress(email, false), "Preferred");
}
else
{
if (emailFacet.PreferredEmail?.SmtpAddress == email)
{
return;
}
emailFacet.PreferredEmail = new EmailAddress(email, false);
}
client.SetEmails(contact, emailFacet);
}
Any help would be highly appreciated :).