I created a custom contact facet
and deployed it. Due to certain requirements, I need to change the data type from bool to string
for those facets.
Do you see any challenges there? And how I can mitigate it?
I am using Sitecore 9.0.2
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communityUnder most circumstances this is a horrible idea. The reason is if you change from a string
to a bool
or a string
to an int
, when the Newtonsoft deserializer runs in xConnect, it will result in this error.
Sitecore.XConnect.Operations.DependencyFailedException: One or more dependencies failed ---> System.InvalidCastException: Specified cast is not valid.
And the worst part is the only way to recover from this is to edit the SQL facets directly. Also once you have a bad facet in your xConnect data, your indexer service is stuck with the exact same error. It's a big flaw in xConnect if you ask me. Sitecore support said I could use the Extraction API to update the broken facets directly, but that doesn't make sense to me. Since the extraction API still deserializes the models.
In your case you can change from a bool to a string, since when the facet is deserialized your string prop will just be "true" or "false".
I would recommend removing your current bool
property and add a new one with a different name. Over time all your facets will be rewritten and the new property will take over.
You can extend your model adding a new field and make a new model. Then you will have the old and new models in xConnect. I have never tried this.
XdbModelBuilder modelBuilder = new XdbModelBuilder("TrialDataModel", new XdbModelVersion(1, 2));
You can find the user in Experience Profile and click the anonymize button. This will also clear any bad facets. Then you indexing can continue again.
You need to deploy it again after changing the data type.
Deploy custom Facet model to XDB
To Deploy the custom facet model to XDB you need to serialize the collection model in which you defined your custom facet model. To serialize into JSON prefer Console application to generate the JSON file.
class Program
{
static void Main(string[] args)
{
var serlizableModel = XdbModelWriter.Serialize(CustomFacetCollectionModel.Model);
File.WriteAllText(CustomFacetCollectionModel.Model.FullName + ".json", serlizableModel);
}
}
On the execution of the console application, it will generate a JSON file. Copy that JSON file and paste at the below places:
x-connect root path > App_data/Models
x-connect root path > App_data/jobs/continuous/IndexWorker/App_data/Models
You can find more details here Create Custom Facet Model in Sitecore 9
NULL
into the property on your facet if it can't work out what the JSON means. Maybe it will throw a TypeConvertException (or something) but it would surprise me if Sitecore hasn't thought of this.