6

I'm seeing the below error when trying to update a components content field.

This item is localized

I have the following code which strips out the content, calls off to a couple of methods that updates the content source xml to that of replacedContentSource. I only get an error when trying to localize the component. The reason I am having to do this is because the component content source contains component links linking to a publication not in the content master.

public void LocalizeAndAddComponentLinks(CoreServiceClient client, ComponentData component, 
                                         string source)
{
    string contentSource = Tridion.CreateRelatedComponents(client, source);
    string replacedContentSource = Tridion.GenerateTcmIds(contentSource);

    component.Content = replacedContentSource;

    client.Localize(component.Id, new ReadOptions());
    client.Update(component, new ReadOptions());
}

I just don't understand why I'm getting this error, the component isn't localized and I've verified this by checking in Tridion.

  • 1
    This exception can be thrown in case item is local. Also, it's considered a bad practice to use Tridion namespace for something that it not developed by Tridion. Can you check component.IsShared and component.IsLocalized properties? – Andrey Marchuk May 13 '13 at 10:43
  • Thanks user978511, ok I think I've worked out why I'm seeing the error. IsShared and IsLocalized are both false. IsShared is false because component.Id has the location of where the component was created. If I right click on a component where it was created I can't localize it so this means the problem is that I need to specify "where" exactly I want to localize the component. Correct me if I'm wrong? – Ibrar Hussain May 13 '13 at 10:55
  • 4
    You now specify component.Id. You'll indeed need to specify where you want to localize the component. Change the Publication ID of that URI to the publication you want to localize into and you should be good to go. – Frank van Puffelen May 13 '13 at 11:49
  • Thanks Frank, I would have accepted your comment as the answer but can't so will add one in myself. – Ibrar Hussain May 13 '13 at 16:17
3

Thought I'd add the answer to this question so everyone knows where the problem was.

Basically I have this client.Localize(component.Id, new ReadOptions()); meaning I want to localize the component at the level it has been created. This won't work and you can test this by going to the component in Tridion - right click on the component and try to localize, it won't work as the option is grayed out.

So I need to change this line of code to specify the publication Id of where I want to localize this component as already pointed out by Frank too!

I will probably do a .Replace() and strip out the publication Id changing it for my target publication.

UPDATE

Just wanted to share my answer to show you how I've got this working by using a .Replace()

    public void LocalizeAndAddComponentLinks(CoreServiceClient client, ComponentData component, string source)
    {
        string contentSource = Tridion.ReplaceSystemComponentIdsWithWebsiteMasterId(client, source);
        var localizedComponent = (ComponentData)client.Localize(component.Id.Replace("tcm:xxx-", "tcm:xxx-"), new ReadOptions());
        localizedComponent.Content = contentSource;

        client.Update(localizedComponent, new ReadOptions());
    }

As pointed out by user978511 using a .Replace() might not be the best approach so I will bed taking a look at the .GetTcmUri method to improve my code.

| improve this answer | |
  • 1
    Instead of replace, consider .GetTcmUri method – Andrey Marchuk May 14 '13 at 6:47

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.