6

Leaning rather heavily on Chris Morgan's WebdavURL bookmarklet, I set out to make one which would copy the human-readable path to an item (which might be preferred by non-techies in documentation)

A quick detour to the anguilla documentation found me the methods .calculatePath() and .getTitle() - a quick regex-strip and all would be good.... here's the code (with some added whitespace goodness)

javascript: (function (UI, B, e, a, r, d) { 
    try { 
        while (r = UI.frames[e++]) { 
            if ((a = r.$display && r.$display.getView()) && a.getId() == B) { 
               d = a; break; 
            } 
        } 
        var m1 = window.top.frames[1]; 
        var itemId = d.getMainInterface().getListSelection().getVersionlessIds()[0]; 
        var item = m1.$models.getItem(itemId); 
        if(item != undefined) { 
            item.loadWebDavUrl(); setTimeout(function() { 
                var itemPath = item.calculatePath()
                      .replace(/^\\Content Management/, "")+"\\"+item.getTitle(); 
                alert(itemPath); 
            }, 400); 
        } else {  
            alert('Please select an item...'); 
        } 
    } catch (x) {
        alert('Please select an item...');
    }; 
})(window.top, 'DashboardView', 0) 

Unfortunately, while .calculatePath() works like a dream, .getTitle() seems only to work some of the time, so on other occasions I just get 'undefined' for the title. So far, I have not been able to identify, say, a particular item type that is doomed to failure. It appears to be random, no matter how alien a world-view this may be for me.

I would love to blame Tridion (maybe select is broken), but I fear it is my own interpretation of scripture that is at fault. Can anyone steer me from the rocky path of waywardness?

5
  • 1
    Could it be something to do with the asynchronous nature of Anguilla?
    – Will Price
    Commented Mar 4, 2015 at 22:36
  • Quite possibly, Will. Do you know of any documentation that shows sensible patterns for using this API? Commented Mar 4, 2015 at 22:42
  • Will might have a point there, but I'm unsure if .getTitle() needs a loaded item or should always have a result. See tridion.stackexchange.com/questions/2695/… for an example of how to load an item. Commented Mar 5, 2015 at 9:48
  • Nice bookmarklet. What did you change for your working solution? item.load instead of .loadWebDavUrl? Oh and a tip for using this--the Chrome browser pop-up doesn't look like it has selectable text but you can still copy the path this generates. Commented Mar 19, 2015 at 18:52
  • getStaticTitle () did the trick. Commented Mar 19, 2015 at 20:37

2 Answers 2

6

loadWebDavUrl doesn't actually load other properties. So you are getting inconsistent results based on whether or not the item has already been loaded.

To solve it, you'll need to call load() on the item instead and wait for the "onload" event to fire. Then the title will be freshly loaded and available.

Alternatively, you could try just using the static title instead (which is probably available since you selected the item in a list)

1
  • 1
    Just using getStaticTitle() did the trick. I've accepted your answer, but equal credit to Siva, whose answer was also helpful. Commented Mar 6, 2015 at 10:59
6

Apart from @Peter answer, I want to add some more points to it.

To get title of an item, you can write as follows:

var title = item.getTitle() || item.getStaticTitle();

With this line of code, you will always get the title either from the cached or from the loaded item.

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.