To add a new facet as a mapping field:
- In the Core database, in the Content Editor, navigate to the
/sitecore/client/Applications/List Manager/Dialogs/ImportWizardDialog/PageSettings/TabControl Parameters/Map/ImportModel folder
and Create a new Import model field item based on the /sitecore/client/Applications/List Manager/Templates/ImportModelField
template.
- In the
FieldName
field, specify the name of the Sitecore mapping field to display in the Import contacts wizard. In the DataField
field, specify the key that the Facet Mapper uses to recognize the xConnect facet property of where to store the imported value. eg. CustomerStatus
is the custom facet that I want to map.
- Now create a custom import mapper class implementing
Sitecore.ListManagement.XConnect.Web.Import.IFacetMapperSitecore.ListManagement.Import.IFacetMapper
. Build this project and deploy the DLL to Sitecore root bin folder.
class CustomerStatusFacetMapper: IFacetMapper
{
private const string FacetMapperPrefix = "CustomerStatus_";
public CustomerStatusFacetMapper() : this("CustomerStatus")
{
}
public CustomerStatusFacetMapper(string facetName)
{
Assert.ArgumentNotNull(facetName, nameof(facetName));
this.FacetName = facetName;
}
public string FacetName { get; }
public MappingResult Map(string facetKey, Facet facet, ContactMappingInfo mappings, string[] data)
{
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry("CustomerFacetMapperCalled facetKey:" + facetKey + " data" + string.Join("; ", data));
}
if (facetKey != this.FacetName)
{
return new NoMatch(facetKey);
}
CustomerStatus customeruser = new CustomerStatus();
string customerStatus = mappings.GetValue(FacetMapperPrefix+nameof(customeruser.Status), data);
Log.Info("Facet Mapper: " + FacetMapperPrefix + nameof(customeruser.Status), this);
if (!string.IsNullOrEmpty(customerStatus)) { customeruser.Status = customerStatus; }
return (MappingResult)new FacetMapped(facetKey, (Facet)customeruser);
}
}
- Create a patch to register the mapper. This patch is extending
Sitecore.ListManagement.config
file (/App_Config/Sitecore/ListManagement), sitecore/import/facetMapper
section. Add the custom facet name to extend the list of facets to map to.
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore role:require="Standalone or ContentManagement">
<settings>
<setting name="ListManagement.Import.FacetsToMap" value="Emails|Personal|Addresses|CustomerStatus" />
</settings>
<import>
<facetMapper type="Sitecore.ListManagement.XConnect.Web.Import.CompositeFacetMapperCollection, Sitecore.ListManagement.XConnect.Web">
<param resolve="true" type="Sitecore.Abstractions.BaseLog, Sitecore.Kernel"/>
<facetMappers hint="list:Add">
<facetMapper type="MA.CustomMarketingApps.Mappers.CustomerStatusFacetMapper, MA.CustomMarketingApps" />
</facetMappers>
</facetMapper>
</import>
</sitecore>
</configuration>
- Now in the ListManager dashboard, create a list from the file. And browse for CSV (CSV should have data against headers Email, FirstName, LastName, NickName, CustomerStatus), Map the fields.
After doing all these, you'll be able to correctly import custom facets via list manager CSV upload.
Refer to this blog for more details: https://sitecorewithraman.wordpress.com/2021/03/27/customize-list-manager-part-ii/