My schema was using a text field whose value was a TCM ID of another related component. Unfortunately, I realized after creating a lot of components that I should have created this relationship using a component link.

I have updated my schema to include a component link while preserving the existing text field.

If you were in my shoes, how would you update these thousands of components?


What Mark says is indeed the way to go - use core services to write a script that does the update for you.

I would work as follows:

  • Create a new field in your schema for the component link, and keep the text field
  • Build a core service script that does the following
    • get all components that use the schema (using code example below)
    • get the TCM id from the text field value, and use this to update the componentlink field, and save the component
  • update any template or code that uses the old field, to use the new field
  • finally remove the old field

sample code to get any items using the schema:

UsingItemsFilterData usingItemsFilterData = new UsingItemsFilterData();
var itemsUsingSchema = client.GetListXml(tcmID, usingItemsFilterData);  
foreach(item in itemsUsingSchema) //pseudo code, you should parse the xml and get the elements
   //open component
   //read value of text field
   //set value of componentlinkfield to tcm id
   //save and check in component

edit : if you are looking for the core service API documentation, you can find this here : https://docs.sdl.com/LiveContent/content/en-US/SDL%20Web-v5/GUID-2301148A-E3EA-43EF-A2FC-7D3C9BAEE8FF


Use the core service to grab the tcmid from the text field and and format the necessary syntax to pop that as the component link directly into the new field.

A few simple Google’s will serve the format/structure you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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