4

I have one Sitecore Register Form (not with WFFM). When user Register, I am trying to send confirmation email. However, somehow this is not working for the first time. My contact is not receiving verification email.

This is what briefly I am doing

  • Identify contact using identify method
  • Set preferred email address by setting up Facet on contact if not already set
  • and then use EXM send standard message passing message id and current contact.

I suspect this is because there is no Facet is stored in Mongo contact for the first time. At least I did not see using Robo Mongo. After Session End Contact data will be flushed to Mongo. When visitor does registration again, this time contact has Email Facet and able to receive registration email.

Appreciate any help on this

3

You can force the contact email into xDB so it will be available during the session.

Contact contact = Tracker.Current.Session.Contact;

//update email in xDB
var recipientRepository = RecipientRepository.GetDefaultInstance();
RecipientId recipientId = new XdbContactId(contact.ContactId);
recipientRepository.UpdateRecipientEmail(recipientId, emailAddress);

Contact Repository Example:

public class ContactRepository
{
    private readonly RecipientRepository _recipientRepository;

    public ContactRepository()
    {
        _recipientRepository = RecipientRepository.GetDefaultInstance();
    }

    protected Sitecore.Analytics.Tracking.Contact CurrentContact
    {
        get { return Tracker.Current != null && Tracker.Current.Session != null ? Tracker.Current.Session.Contact : null; }
    }

    /// <summary>
    /// Identifies the current contact using the provided email string
    /// and forces that email into xDB
    /// </summary>
    /// <param name="email">identifier string</param>
    public void SetIdentifier(string email)
    {
        Tracker.Current.Session.Identify(email);

        var recipientId = new XdbContactId(CurrentContact.ContactId);
        _recipientRepository.UpdateRecipientEmail(recipientId, email);
    }
}

The ContactRepository is a dependency of any component or other fixture that needs to use or interact with contact information.

The RecipientRepository can be a dependency of the ContactRepository, instantiated in its constructor.

This class can also be used to manage existing or custom contact facets such as PersonalInfo, EmailInfo, etc.

  • Is there any other alternate way we can achieve this? I will go with this as a last option. – Mohit Dharmadhikari Jun 9 '17 at 23:24
  • 1
    @MohitDharmadhikari: I updated the answer with an example of the implementation. I hope that helps! – Nathan Hase Jun 12 '17 at 12:55
  • When I do this I get the error Updating email of contact {_GUID_} failed. The contact was locked by another process. – user1069816 Jun 5 '18 at 9:47
  • 1
    @user1069816 It sounds like you have other code (something like ContactManager.TryLoadContact) that is loading the contact, which locks the contact record in the Collection DB and the Shared Session. If you use ContactManager.SaveAndReleaseContact(), this will release the lock in the shared session but not the Collection DB, which will remain locked until the Shared Session expires. The correct way to release a contact is ContactManager.SaveAndReleaseContactToXdb(). See sitecore.stackexchange.com/questions/3233/… for more details. – Nathan Hase Jun 5 '18 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.