• Not Answered

Using WFFM Update Contact Details save action

Hello,

There is an "Update Contact Details" WFFM save action in Sitecore 8.0-8.1, which allows populate contact with facet data. 

However, this action does not work in all cases.
If one adds only this action to the form and configure it to update some specific contact facets, the data won't be updated and there will be the following record in the log file:

[UPDATE CONTACT DETAILS Save action] User is not authenticated to edit contact details.

The form action code looks like as follows (retrieved using .NET Reflector in WFFM 8.1 Upd.1):

protected virtual void UpdateContact(AdaptedResultList fields)
{
Assert.ArgumentNotNull(fields, "adaptedFields");
Assert.IsNotNullOrEmpty(this.Mapping, "Empty mapping xml.");
Assert.IsNotNull(this.analyticsTracker.CurrentContact, "Tracker.Current.Contact");
if (!this.authentificationManager.IsActiveUserAuthenticated)
{
this.logger.Warn("[UPDATE CONTACT DETAILS Save action] User is not authenticated to edit contact details.", this);
}
else
{
IEnumerable<FacetNode> enumerable = this.ParseMapping(this.Mapping, fields);
IContactFacetFactory contactFacetFactory = this.facetFactory.GetContactFacetFactory();
Contact currentContact = this.analyticsTracker.CurrentContact;
foreach (FacetNode node in enumerable)
{
contactFacetFactory.SetFacetValue(this.analyticsTracker.CurrentContact, node.Key, node.Path, node.Value, true);
}
this.contactManager.SaveAndReleaseContactToXdb(currentContact);
}
}

Thus, the contact data is not updated if the current user is not authenticated. This authentication checkup was added due to security reasons.

There are several ways to make the action work as expected:

1. Create a custom WFFM action. The example of the action can be found below:
  1) Create a new class inherited from the Sitecore.WFFM.Actions.SaveActions.UpdateContactDetails (Sitecore.Form.Submit.UpdateContactDetails in WFFM 8.0) one.
  2) Override the UpdateContact method like follows:

protected virtual void UpdateContact(AdaptedResultList fields)
{
Assert.ArgumentNotNull(fields, "adaptedFields");
Assert.IsNotNullOrEmpty(this.Mapping, "Empty mapping xml.");
Assert.IsNotNull(this.analyticsTracker.CurrentContact, "Tracker.Current.Contact");
this.logger.Warn("[UPDATE CONTACT DETAILS Save action] User is not authenticated to edit contact details.", this);
IEnumerable<FacetNode> enumerable = this.ParseMapping(this.Mapping, fields);
IContactFacetFactory contactFacetFactory = this.facetFactory.GetContactFacetFactory();
Contact currentContact = this.analyticsTracker.CurrentContact;
foreach (FacetNode node in enumerable)
{
contactFacetFactory.SetFacetValue(this.analyticsTracker.CurrentContact, node.Key, node.Path, node.Value, true);
}
this.contactManager.SaveAndReleaseContactToXdb(currentContact);

}

  Please note that the code may differ depending on your Sitecore version and revision. You need to copy the default UpdateContactDetails.UpdateContact method implementation and remove the "if" part from it.
  You can get the UpdateContactDetails class code using .NET Reflector, IL Spy or any other similar tool.
  3) Build the assembly and put it in the bin folder.
  4) Create a new Z.Sitecore.WFFM.UpdateContactDetails.config file in the App_Config/Include folder
  5) Add the following markup to it:

<?xml version="1.0" encoding="utf-8"?>

<configuration xmlns:patch="www.sitecore.net/xmlconfig">
<sitecore>
<wffm>
<actions>
<updateContactDetails type="Sitecore.WFFM.Actions.SaveActions.UpdateContactDetails, Sitecore.WFFM.Actions">
<patch:attribute name="type">YourNamespaceName.YourClassName, YourAssemblyName</patch:attribute>
</updateContactDetails>
</wffm>
</sitecore>
</configuration>

  Please note that the patch config file must be applied after the Sitecore.WFFM.Dependencies.config one (the file name is important.
  Please note that in WFFM 8.0, the action classes are taken from the save action items and steps 4-5 must be replaced with the following ones:

  4) In the Content Editor navigate to the /sitecore/system/Modules/Web Forms for Marketers/Settings/Actions/Save Actions/Update Contact Details item.
  5) Change the item fields as follows:

  Assembly: YourAssemblyName
  Class: YourNamespaceName.YourClassName

  6) Publish the item.


2. Use the following bunch of actions on the form:
  "Create User"
  "User Login"
  "Update Contact Details"

The second approach does not require writing custom code, however a new user will be created after filling a form, which may be unacceptable

Please let me know if this post helped you and feel free to ask me if you have any questions regarding it.

Best regards
Sergey

1 Reply

  • The change you suggest does allow an xDB contact to be created; However it will not allow it to work with some engagement plan actions. The engagement plan will not have the correct updated contact. The UX shows it does but the Send EXM Email errors out stating it can't find the username.

    For Sitecore to update the contact before it gets added to the engagement plan you need to call Sitecore.Analytics.Tracker.Current.Session.Identify() with the email address in the UpdateContact method.

    I just wanted to add this in case someone else runs into the same problem.