Sitecore 8 – Extending Experience Profile – Part 2 – Displaying Contact Facet Simple Properties

How to display contact facet simple properties

End result:

end-result

There’s a good reference on how to create a custom tab in Sitecore Experience Profile on Jonathan Robbins blog post,  I recommend you go and read it through.

How to set this up

Source code link is available at the end of this post.

How to setup the custom contact facet

There’s a good reference on Sitecore documentation site on how to do so.

In my custom facet I only have two properties, which is the HospitalName and the ProfessionName.

ICustomFieldsFacet.cs

 

CustomFieldsFacet.cs

 

And the config patch file to register this custom facet

TC.Sitecore.Analytics.Model.config

 

To fillout the data in the custom facet I’ve setup a page to do this

updatecontact-page

 

How to setup the web API controller

First we need to register our custom route to our custom controller

InitializeRoutes.cs

 

In our custom controller, we just return the custom facet that contains all the properties that we want to display in Experience Profile

CustomContactController.cs

 

Finally we add the InitializeRoutes class to the pipeline

TC.Sitecore.ExperienceProfile.config

 

How to setup a custom tab in Experience Profile

I will not go in detail on how I setup the content tree as the reference I’ve provided should give you an idea on how to set it up and I’ll be providing the source code at the end of this post.

This is the content tree in the core database that I’ve setup in order to display those 3 tabs

professionpanel-contenttree

The first tab which is the Profession tab will be displaying the custom field from the custom contact facet that I’ve setup.

The rendering items

 

Wire things together

To display this information, after our Profession tab is loaded in the Experience Profile we would need to call our CustomContactController class to retrieve the data.

The code that’s responsible to do this is the profession.js that is set in the SubPageCode rendering control in the ProfessionPanel layout. This javascript file is executed when the ProfessionPanel item is loaded into the Profession tab

professionpanel-layout-subpagecode

profession.js

 

The script basically calls an API method in the server which then gives back the response in a JSON format which we then assign to the controls defined in the ProfessionPanel item layout.

customfields-webapi-call-request

This is the full url it’s trying to access http://habitat.dev.local/sitecore/api/ao/v1/contacts/02b2e6c4-d38a-4e30-a18e-b4a31b63907d/customfields/

It’s passing the current contact id and a specific url ‘customfields’ which we route to our custom web API controller. It will then use the cintelUtil helper to bind the data to the text controls defined in our ProfessionPanel layout.

 

Source code

Source code is available in Github

One thought on “Sitecore 8 – Extending Experience Profile – Part 2 – Displaying Contact Facet Simple Properties

  1. I get the following error as soon as i click on the custom tab in experience profile:

    Uncaught Error: Unable to parse bindings.
    Message: ReferenceError: IsVisible is not defined;
    Bindings value: visible: IsVisible, text: Text, attr: {title: Tooltip()}
    at ko.bindingProvider.parseBindingsString (knockout-2.2.1.js:1936)
    at ko.bindingProvider.getBindings (knockout-2.2.1.js:1916)
    at ko.bindingProvider.result.getBindings (sitecore-1.0.2.js:147)
    at ko.dependentObservable.disposeWhenNodeIsRemoved (knockout-2.2.1.js:2067)
    at evaluateImmediate (knockout-2.2.1.js:1241)
    at Object.ko.dependentObservable (knockout-2.2.1.js:1318)
    at applyBindingsToNodeInternal (knockout-2.2.1.js:2051)
    at applyBindingsToNodeAndDescendantsInternal (knockout-2.2.1.js:2019)
    at Object.ko.applyBindings (knockout-2.2.1.js:2138)
    at child.sync (sitecore-1.0.2.js:657

    Please help what could be wrong.

Leave a Reply

Your email address will not be published. Required fields are marked *