SDL Tridion Bookmarklet Challenge Entry - Rename Tridion Item

Way back in August, one of the SDL Tridion MVPs - Dominic Cronin, proposed a challenge to the SDL Tridion community. The challenge was to create a bookmarklet to perform something useful in the SDL Tridion GUI.

A bookmarklet is a small piece of JavaScript code which executes as a bookmark within the browser to give you a bit of functionality that wasn't already there. There are many general ones around on the internet that can do all sorts of things.

The challenging part of this challenge was definitely thinking of something to do in SDL Tridion. Bookmarklets are not GUI Extensions, they need to be really, really simple. The idea is to save you a few clicks or perform some repetivie actions - like a macro in a text editor.

I tried a couple of ideas and then hit on renaming items! Quite often I spot a Component Template not following naming conventions and want to quickly rename it but you have to open the item and then save it. It's like 3 steps - I reckoned I could make that easier.

So my entry is Rename Tridion Item

Disclaimer: this code is not production quality and has only been briefly tested on a dev environment - I suggest that you do the same as it may automatically check in items depending on your permissions. I am not responsbile for any data loss! Only tested on SDL Tridion 2013 SP1.

Instructions: 

  • Focus an item in the dashboard view and click the link.
    focus
  • A prompt will appear like this (old school!)
    prompt
  • Enter the new name and click OK and the item is renamed
    renamed

To install:

  1. Create a new bookmark in your browser called "Rename Tridion Item"
  2. Add the following to the link field:
    javascript:(function(e,t,n,r,i,s){try{while(i=e.frames[n++]){if((r=i.$display&&i.$display.getView())&&r.getId()==t){s=r;break}}var o=s.getMainInterface().getFilteredListControl().getList().getFocusedItem();var u=i.$models.getItem(o);if(u!==undefined){u.load();var a=prompt("Enter a new name for "+u.getTitle());if(a!=null&&a!==undefined){u.setTitle(a,true);u.save(true);u.setChanged()}}else{alert("No item selected")}}catch(f){}})(window.top,"DashboardView",0)
  3. Save

I've minifed the code here - so you can't actually see what it does, full source below. This raises a good point about the security of bookmarklets - you're running someone elses code in the browser. Some bookmarklets even load external JavaScript files so you should always be very careful with them.

Here's the full code:

[gist]https://gist.github.com/rsleggett/e74618a915da79eb3e3d[/gist]

I followed the process in this article: http://code.tutsplus.com/tutorials/create-bookmarklets-the-right-way--net-18154

I found it quite difficult to develop as I haven't done any GUI Extensions for a while so remembering how it all worked was challenging but a lot of fun.

Merry Christmas!

Any questions?

If you need more information or have any questions just get in touch and we'd be happy to answer them for you.