2

I came across few posts where users had tcm IDs in the component fields (Either entered manually or picked by applications like Item Selector).

Most of them faced problem while migration or upgrade and felt the need to replace TCM Ids with webdav path.

I wanted to understand how can we get the Webdav path instead of TCM ID in the item selector application?

P.S. At present, We do not have any TCM ID in any fields of the components. But should we plan to use Item selector, Will it be wise to use webdav path instead of TCM Id?

1 Answer 1

5

If you look at the source code of the Item Selector (https://github.com/bkoopman/sdl-tridion-world/blob/master/Item%20Selector/trunk/SDLTridion.Examples.ItemSelector/UserControls/TridionTreeView.ascx.cs) you might notice the following:

private TreeNode CreateTreeNode(string nodeText, string nodeValue)
{
    TcmUri uri = new TcmUri(nodeValue);
    if (uri.ItemType == ItemType.WorkItem)
    {
        if (!_showItemTypes.Contains(ItemType.Category))
        {
            return null;
        }
    }

    if (!_showItemTypes.Contains(uri.ItemType))
    {
        return null;
    }

    TreeNode tNode = new TreeNode(nodeText, nodeValue) { Expanded = false, ImageUrl = UriImage(uri) };

    switch (uri.ItemType)
    {
        case ItemType.Publication:
        case ItemType.Folder:
        case ItemType.StructureGroup:
        case ItemType.Category:
        case ItemType.Keyword:
        case ItemType.WorkItem:
            tNode.PopulateOnDemand = true;
            break;
        default:
            tNode.PopulateOnDemand = false;
            break;
    }

    if (!_selectedItemTypes.Contains(uri.ItemType))
    {
        // disable select action (set to expand)
        tNode.SelectAction = TreeNodeSelectAction.Expand;
    }
    else
    {
        // call javascript from navigate url to prevent post (post will loose window.dialogarguments)
        tNode.NavigateUrl = "javascript:setvalue('" + nodeValue + "');";
    }

    return tNode;
}

In the end you see the generation of the javascript callback with the nodeValue, which currently is the TCM URI.

If you want to return a WebDAV URL, that javascript line is what you should change, by getting the WebDAV URL from the item, something like this should do the trick I guess:

 RepositoryLocalObjectData item = (RepositoryLocalObjectData)_client.Read(nodeValue, new ReadOptions());
 tNode.NavigateUrl = "javascript:setvalue('" + item.LocationInfo.WebDavUrl + "');";

To answer your question if it is wise to use a WebDAV URL, rather than a TCM URI. To be honest, it is never a good idea to link to any item using an unmanaged link. The Item Selector does exactly that, it creates an unmanaged link, by pasting a reference to an item in a text field. But the reality is, that sometimes this is your only option.

I built the Item Selector as an example of how to use the Core Service in a Custom Page (or Custom URL in this case actually). It serves a useful purpose as an Item Selector, which complemented the Rapid Editorial Interface event system I built before it. You are free to use it as is or modify any way you like (for instance by returning the WebDAV URL like explained above). But keep in mind what you are doing with regards to unmanaged links, and know what concequenses that has. That being said, a WebDAV URL might indeed be a better solution than the TCM URI, if you need to port this information between environments.

1
  • Thanks a lot. This worked. True that the unmanaged links look tricky. We have a situation where Editors would like to have a direct Page linking rather than Component linking. They are not very comfortable with the concept of component linking. So I was exploring different options.... Any other solution could be useful..in case there are other ways to implement this. Commented Oct 5, 2015 at 9:49

Your Answer

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

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