Get interaction facets
You must specify which facets should be returned with an interaction or batch of interactions by passing an array of facet keys into the InteractionExpandOptions.
In the following example, the default IpInfo facet is requested as part of the interaction expand options:
A facet is added to the interaction’s Facets dictionary if the facet exists for that interaction. If the facet you requested is not defined in the model, xConnect will throw an exception when the request is executed. When the interaction or interactions have been returned, use the .GetFacet<T>() method on the interaction to retrieve the facet object:
The method .GetFacet<T>() will return null if:
-
The facet was not requested as part of the
InteractionExpandOptionswhen the interaction was initially retrieved -
The facet has not set for a particular interaction
-
The combination of type and key is incorrect
The following example demonstrates how to retrieve and work with the IpInfo facet:
All built-in facet models have a DefaultFacetKey property - for example, WebVisit.DefaultFacetKey.
Get facets using the default facet key
Get facets using the default facet key
All built-in facet models have a FacetKey attribute that associates the default facet key with the facet model.
If a facet key is not specified, xConnect will fall back to the default value. Add the FacetKey attribute to your own facet models to mimic this behavior. In the following example, .Expand<IpInfo>() and .GetFacet<IpInfo>() are used without specifying a facet key.
An exception will be thrown if the facet model does not have a FacetKey attribute.
If you have used a facet model (such as IpInfo) to define multiple facets, consider storing the non-default facet keys as constants in your model class.
Setting interaction facets and adding events
You must use the .SetFacet() extension method to set contact facets. For more information, see:
Interaction facets cannot be updated once they have been set.