I have cloned this repo and updated it to run with Sitecore 10.1 (which is our current version): https://github.com/adeneys/cortex-processing-demo
The above application has functionality to create a custom model 'MusicPurchaseOutcome' and generate the necessary JSON to deploy to Xconnect (which I have deployed to App_data/Models). The above model also maps to a Outcome which I have created in Sitecore and deployed.
The application also allows to register mock interactions into XConnect using this custom model. The code to do this can be seen below:
var xConnectClient = await CreateXConnectClient();
var contactId = new ContactIdentifier("music", Guid.NewGuid().ToString(), ContactIdentifierType.Known);
var contact = new Contact(contactId);
contacts.Add(contact);
var album = albums[random.Next(0, 3)];
var outcome = new MusicPurchaseOutcome(DateTime.Now, "GBP", 20)
{
Album = album
};
var interaction = new Interaction(contact, InteractionInitiator.Contact, _channelId, "music kiosk 1.0");
interaction.Events.Add(outcome);
xConnectClient.AddContact(contact);
xConnectClient.AddInteraction(interaction);
await xConnectClient.SubmitAsync();
I can confirm that this successfully adds an interaction to XConnect, example below shows the value in 'Events' column of an interaction:
[{"@odata.type":"#ProcessingEngineDemo.XConnectExtensions.MusicPurchaseOutcome","CustomValues":[],"DefinitionId":"01de8c58-ac29-4bd7-a893-fc2d853bd53e","Id":"3b8feb8f-b7de-441c-9265-cf8c8f997c58","Timestamp":"2022-06-27T07:20:20.2615588Z","CurrencyCode":"GBP","MonetaryValue":"20","Album":{"ArtistName":"Muse","ArtistId":"12Chz98pHFMPJEknJQMWvI","AlbumName":"Drones","AlbumId":"2wart5Qjnvx1fd7LPdQxgJ"}}]
The problem I am facing is when I come to search XConnect and try to return contacts that have interactions of this new custom type. Using the code below:
var xConnectClient = await CreateXConnectClient();
var query = xConnectClient.Contacts.Where(contact =>
contact.Interactions.Any(interaction =>
interaction.Events.OfType<MusicPurchaseOutcome>().Any() && interaction.EndDateTime > DateTime.UtcNow.AddMinutes(-TimeoutIntervalMinutes)
)
);
var expandOptions = new ContactExpandOptions
{
Interactions = new RelatedInteractionsExpandOptions()
};
query = query.WithExpandOptions(expandOptions);
var batchEnumerator = await query.GetBatchEnumerator();
System.Console.WriteLine($"Found {batchEnumerator.TotalCount} interactions");
while (await batchEnumerator.MoveNext())
{
foreach (var contact in batchEnumerator.Current)
{
System.Console.WriteLine("====================================");
System.Console.WriteLine($"Contact ID {contact.Id}");
var outcomes = contact.Interactions.SelectMany(i => i.Events.OfType<MusicPurchaseOutcome>());
foreach (var outcome in outcomes)
{
var album = outcome.Album;
System.Console.WriteLine("------------------------------------");
System.Console.WriteLine($"Album Id: {album.AlbumId}");
System.Console.WriteLine($"Album Name: {album.AlbumName}");
System.Console.WriteLine($"Artist Id: {album.ArtistId}");
System.Console.WriteLine($"Artist Name: {album.ArtistName}");
}
}
}
The above code returns 0 contacts. However, if I change the call to XConnect (line 4) to get of type 'Event':
Events.OfType<Event>
The second call (line 22):
Events.OfType<MusicPurchaseOutcome>()
Is able to successfully identify those events that are of type 'MusicPurchaseOutcome'. I can only assume that the custom model isnt correctly deployed somehow, which is why it isnt working in the remote call. But the second call works because it is performed locally after it has been returned from XConnect?
There are no exceptions being registered in the logs when I make the above calls to XConnect.
Any suggestions on what might be causing the initial call to fail would be greatly appreciated.