10

I have a problem creating components using the coreservice. I create components with code on master level(tcm:76). The given source code of the master component is correct, but when viewing this component on another level like tcm:6,.. the links in the source code won't change. until I open the component and press the save button in tridion itself. I don't wan't to do this for all the components I create because this is a lot of work. (+- 1000 items.) Does anybody knows the answer for this?? Thanks in advance

 protected ComponentData createImageComponent(Image image, string schemaId, string locationId, ICoreService client) {
        try {

            SchemaData schemaData = client.Read(schemaId, new ReadOptions()) as SchemaData;
            string uuid = schemaData.NamespaceUri;
            ComponentData component = (ComponentData)client.GetDefaultData(ItemType.Component, locationId);
            component.Id = "tcm:0-0-0";
            component.Title = image.imageTitle;
            component.Schema = new LinkToSchemaData { IdRef = schemaId };
            StringBuilder sb = new StringBuilder();
            image.changeTo76();
            sb.Append("<Content xmlns=\"").Append(uuid).Append("\"><ThumbSource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"");
            sb.Append(image.thumbSource).Append("\" xlink:title=\"").Append(image.thumbTitle).Append("\"></ThumbSource><PhotoSource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"");
            sb.Append(image.imageSource).Append("\" xlink:title=\"").Append(image.imageTitle).Append("\"></PhotoSource></Content>");


            component.Content = sb.ToString();
            component.LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = locationId } };

            ComponentData componentData = (ComponentData)client.Create(component, readOptions);

            return componentData;

        } catch (Exception e) {
            txtConsole.ForeColor = Color.Red;
            txtConsole.Text += "\n Exception createImageComponent \n StackTrace: \t" + e.StackTrace.ToString() + " Message: " + e.Message.ToString();
            txtConsole.ForeColor = Color.Black;
            return null;
        }

    }

This code will create a component on our 'Master' level. with 'tcm:76' which is correct.

<Content xmlns="uuid:e0bc7848-a25a-41b0-8f02-ac4e1d4250bb">
            <ThumbSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:76-mm01-554-dist-file" xlink:title="120x85_17.jpg"></ThumbSource>
            <PhotoSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:76-mm01-579-dist-file" xlink:title="685x555_17.jpg"></PhotoSource>
        </Content>

When I open this component on another level with "tcm:6", I retrieve this source which is wrong: the href still gives back ecl:76 while it must return ecl:6!

<Content xmlns="uuid:e0bc7848-a25a-41b0-8f02-ac4e1d4250bb">
            <ThumbSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:76-mm01-554-dist-file" xlink:title="120x85_17.jpg"></ThumbSource>
            <PhotoSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:76-mm01-579-dist-file" xlink:title="685x555_17.jpg"></PhotoSource> </Content>

If I open this component on master level in tridion(no coding). I enter a whitespace in the description of the component en delete this back.(need to edit something to be able to save the component). Then I press the "save" button in tridion and look back to the source. it returns the correct source:

<Content xmlns="uuid:e0bc7848-a25a-41b0-8f02-ac4e1d4250bb">
            <ThumbSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:6-mm01-554-dist-file" xlink:title="120x85_17.jpg"></ThumbSource>
            <PhotoSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:6-mm01-579-dist-file" xlink:title="685x555_17.jpg"></PhotoSource>
        </Content>
1
  • Please submit this to customer support. Looks like an ECL specific bug related to resolving Blueprinted item URIs. Thanks for the very good writeup and code sample. I'm sure it will help customer support reproduce the issue.
    – robrtc
    Jun 27, 2013 at 10:28

1 Answer 1

11

You can only use ECL URIs in the following places:

1) Client side (so in the Anguilla JavaScript code)

2) In DataExtenders placed after the ECL data extenders.

3) In the ECL API (accessible from for example templates)

The Tridion core service simply do not know what an ECL URI is. So your links will be treated as unmanaged links - and unmanaged links do not get the publication updated.

The reason it gets corrected when you save it from the UI is because now your data go through the Anguilla data extenders of ECL. These data extenders recognize the ECL URI and create a TCM component that functions as a stub. It's the URI of this URL that gets saved. If you retrieve the component through the core service after you have saved it in the URI you would see the TCM URI, not the ECL URI. In the UI you always see the ECL URI, as the TCM URI stored in the Tridion database will be converted back to an ECL URI once you load the item.

You have a couple of options on how to proceed.

If it's the same items you want to link to every time, simply hard code the URI of the stub component. To get this you must first ensure a stub is created. An easy way is simply checking out the item in Tridion and then undo checkout. Once this is done the URI of the stub will be on the Info tab of the item in Tridion.

If you need to dynamically locate different ECL items it gets a bit tricky. Unfortunately the ECL Service is not a public API at this moment. This means it's not documented and it might change without notice. You can still call it if you want to but you are on your own getting it working. I would consider trying this out if you are just doing a tool with short life - so not something you need to keep running.

Alternatively you can use the same API you use for writing templates. The EclSession has a constructor that allows you to create a session for a specific user, even if you do not have a TCM session object to begin with. The session object have a method allowing you to get the URI of a stub component - it will create the stub if it doesn't already exist. Notice you will need to make sure your process have the config settings available needed by TOM.NET, and it does unfortunately result in TOM.NET being hosted in your process.

1
  • You saved me! Thanks for the great answer. When creating the component on Master level. I entered the TCMURI instead of the eclUri in the xml. The Anguilla JavaScript code did the rest like you explained. Jun 28, 2013 at 9:19

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.