0

I've changed the Element Root Name of my Schemas and now I want to synchronize my components with their new Root elements.

I'm trying to do it with the CoreService.SynchronizeWithSchemaAndUpdate method. Defining Flags like this:

SynchronizeOptions options = new SynchronizeOptions();
options.SynchronizeFlags = Tridion.ContentManager.CoreService.Client.SynchronizeFlags.FixNamespace;
options.SynchronizeFlags = Tridion.ContentManager.CoreService.Client.SynchronizeFlags.RemoveUnknownFields;
options.SynchronizeFlags = Tridion.ContentManager.CoreService.Client.SynchronizeFlags.ApplyDefaultValuesForMissingMandatoryFields;

And calling:

CoreService.SynchronizeWithSchemaAndUpdate(comp.Id, options);

But it crash giving me this exception:

Unexpected root element: Content. Expected:uuid:fe3b0600-5bfd-4224-b9ef-63c99bbb854e:MiceHPContent.

In this case, old Element Root Name was "Content" and I've changed it for "MiceHPContent". The SynchronizeFlags.FixNamespace flag it shouldn't to fix this problem precisely?

Here its defininiton from http://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20full%20documentation-v1/GUID-9E83FE0C-F650-451F-BEB3-7960A4925D90#docid=GUID-2B44D2F8-65E9-40DD-8408-DF1537BE50F5&filename=GUID-2B44D2F8-65E9-40DD-8408-DF1537BE50F5.xml&query=&scope=&tid=&resource=&inner_id=&addHistory=true&toc=false&eventType=lcContent.loadDocGUID-2B44D2F8-65E9-40DD-8408-DF1537BE50F5:

If the namespace of the content item's root element is not the same as the Schema's, it is set to the Schema's.

How can I synchronize the components?

Thank you.

3
  • I'm not sure a root node name change is covered by synchronizing the namespaces. If you open these Components in the GUI, do the fields disappear? You might need to copy fields using the Core Service instead (maybe from the XML). Apr 21, 2015 at 4:27
  • If I open a component in the GUI, i can save it and it works correctly changing and synchronizing the fields and namespace but i have more than 50000 comps, I can't do it manually and in the description of the flag it seems that could resolve my problem. Thanks for response.
    – Arnau
    Apr 21, 2015 at 8:54
  • Not sure what's wrong, but there's another method, SynchronizeWithSchema, that might work. This takes an IdentifiableObjectData object instead of an ID and doesn't save the changes. Jul 9, 2015 at 16:53

3 Answers 3

3

You are not adding the flags together (using |= for instance), but rather overriding it every time.

Try it like this:

options.SynchronizeFlags = FixNamespace | RemoveUnknownFields | ApplyDefaultValuesForMissingMandatoryFields;
4
  • You are right, but it's still crashing with your fix. Also I have tryed with flag SynchronizeFlag.All, that include all options, and the errors are always the same. It seems that this method not work correctly.
    – Arnau
    Apr 20, 2015 at 14:27
  • Hi Arnau, what version of Tridion are you using, 2013, 2013 SP1 or 2013 SP1 HR1? Apr 20, 2015 at 17:10
  • Hi Elena, I'm using 2013 SP1 HR1
    – Arnau
    Apr 21, 2015 at 7:32
  • It's possible that this method cannot fix the root element name for you (but it can fix other things like the namespace and missing fields). I guess you'll need to do a Where Used and update the root element name for all of the Components yourself. Apr 21, 2015 at 8:54
2

If all you've done is change the root element name, then you could fix them with a fairly simple XSLT, or by loading the XML into your favourite kind of DOM object and manipulating the nodes. A simple core service script would suffice for the task.

To be honest, it sounds like you're tackling it in the wrong order. There's no need to change the schemas before you've figured out how to update the content.

1

A late answer, but there is now an Alchemy tool to automate this process: https://www.alchemywebstore.com/plugins/Component-Synchronizer

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.