I've been following the instructions on how to create custom personalization tokens. After following the instructions everything compiles, and everything seemingly works just fine. I can create a new campaign in EXM and I can send a test mail from "Review". However, the test mail doesn't replace my custom tokens.
Having googled a bit I found this question, which is similar, but not identical. The answer to that question was that the custom facets had not been added to the custom DispatchTask
.
My custom facets, however, have been added to my custom DispatchTask
, and I know that there's nothing wrong with them as I can read and write to them in XConnect and through Tracker.Current.Contact
.
It seems that my CustomDispatchTask
class is never executed, which explains why my custom tokens are not replaced.
/sitecore/admin/showconfig.aspx
shows that my custom class has indeed been patched in:
<exm>
<dispatchTask
type="My.Namespace.CustomTokensDispatchTask, MyAssemblyName"
patch:source="My.EXM.config">
.....
</dispatchTask>
</emx>
But if I try to debug either the constructor or the overridden GetContacts
methods, the breakpoints are never hit. I also added some logging to it (in case this code is executed on AppStart where I won't be able to debug fast enough) but those log messages never appear in the log file. There are actually no exceptions or errors in the log files at all.
Why isn't my CustomTokensDispatchTask
executed?
CustomTokensDispatchTask.cs
public class CustomTokensDispatchTask : DispatchTask
{
private readonly IContactService _contactService;
public CustomTokensDispatchTask([NotNull] ShortRunningTaskPool taskPool, IRecipientValidator recipientValidator, IContactService contactService, EcmDataProvider dataProvider, ItemUtilExt itemUtil, IEventDataService eventDataService, IDispatchManager dispatchManager, EmailAddressHistoryManager emailAddressHistoryManager, IRecipientManagerFactory recipientManagerFactory, SentMessageManager sentMessageManager)
: base(taskPool, recipientValidator, contactService, dataProvider, itemUtil, eventDataService, dispatchManager, emailAddressHistoryManager, recipientManagerFactory, sentMessageManager)
{
Sitecore.Diagnostics.Log.Info("HELLO CustomTokensDispatchTask", this);
_contactService = contactService;
}
protected override IReadOnlyCollection<IEntityLookupResult<Contact>> GetContacts(List<DispatchQueueItem> dispatchQueueItems)
{
Sitecore.Diagnostics.Log.Info("HELLO CustomTokensDispatchTask.GetContacts", this);
return _contactService.GetContacts(dispatchQueueItems.Select(x => x.ContactIdentifier),
PersonalInformation.DefaultFacetKey,
AddressList.DefaultFacetKey,
EmailAddressList.DefaultFacetKey,
ConsentInformation.DefaultFacetKey,
PhoneNumberList.DefaultFacetKey,
ListSubscriptions.DefaultFacetKey,
MyCustomFacet.DefaultFacetKey);
}
}
My.EXM.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns:set="http://www.sitecore.net/xmlconfig/set">
<sitecore>
<exm>
<dispatchTask set:type="My.Namespace.CustomTokensDispatchTask, MyAssemblyName">
</dispatchTask>
</exm>
<recipients>
<recipientPropertyTokenMap set:type="My.Namespace.CustomTokensTokenMap, MyAssemblyName">
</recipientPropertyTokenMap>
</recipients>
</sitecore>
</configuration>
Sitecore 9.0.2
showconfig.aspx
this is indeed patched in correctly. – GTHvidsten Nov 8 '18 at 12:42Tracker.Current.Contact
works just fine – GTHvidsten Nov 8 '18 at 12:54