0

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.

1 Answer 1

0

The problem was config code (that I failed to add to the question), nevertheless I will add as an answer to this, on the off chance anyone has a similar issue.

The repo I was using, was originally created to interact with Sitecore 9.1. In this version, the config required to add a custom model takes the format:

<Settings>
  <Sitecore>
    <XConnect.Client>
      <Services>
        <Client.Configuration>
          <Options>
            <Models>
              <!-- Configure the xConnect client to include the custom model. -->
              <MusicModel>
                <TypeName>ProcessingEngineDemo.XConnectExtensions.MusicModel, ProcessingEngineDemo.XConnectExtensions</TypeName>
                <PropertyName>Model</PropertyName>
              </MusicModel>
            </Models>
          </Options>
        </Client.Configuration>
      </Services>
    </XConnect.Client>
  </Sitecore>
</Settings>

Reference here: https://github.com/adeneys/cortex-processing-demo/blob/master/Processing%20Engine%20Extensions/App_Data/Config/Sitecore/Demo/sc.Customizations.xml

The issue I had, is that it seems the config structure changed when moving to Sitecore 10.1.2 (which is the version I was using). When I updated it to the form as below the event was recognised:

<Settings>
  <Sitecore>
    <XConnect>
      <Services>
        <XConnect.Client.Configuration>
          <Options>
            <Models>
              <CourseCollectionModel>
                <TypeName>ProcessingEngineDemo.XConnectExtensions.MusicModel, ProcessingEngineDemo.XConnectExtensions</TypeName>
              </CourseCollectionModel>
            </Models>
          </Options>
        </XConnect.Client.Configuration>
      </Services>
    </XConnect>
  </Sitecore>
</Settings>

Note that XConnect.Client is renamed XConnect, and Client.Configuration is renamed XConnect.Client.Configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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