7

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

1
  • My initial reaction is that there's no challenge. The custom facets are stored as JSON in the database, and I would imagine the JSON converter that Sitecore uses will put a 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. Nov 18, 2019 at 16:21

2 Answers 2

4

NOOOOOOOO

Under 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".

New property

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.

Add a new version

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));

UPDATE

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.

2
  • Thanks. It seems bool to string is also giving the same error you mentioned for the Newtonsoft. Nov 20, 2019 at 3:32
  • That is unfortunate. I was lucky to catch this in QA before going to prod. If you know what contacts have bad facets, you can try anonymizing them in XP. That should delete the facets. But you lose the contact.
    – Chris Auer
    Nov 20, 2019 at 3:34
0

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

Your Answer

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

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