Dynamics CRM 2013/2015 Open Lookup in New Window Bookmarklet

Paul Nieuwelaar, 13 November 2014

In Dynamics CRM 2013, and also CRM 2015, when we click on the link in a lookup field, the record opens. However, because of the flat UI introduced with CRM 2013, the record opens in the same window as the record you’re currently on. In other words, you’re forced to navigate away from the record you were using.

When you’re filling in a lookup, sometimes you need to click through to the record to make sure you’re picking the right value.

Dynamics CRM 2013 2015 Open Lookup in New Window Bookmarklet

This doesn’t work too well on a create form however, as the record has not been saved yet, so if you navigate away you will lose all the information you’ve just entered.

Dynamics CRM 2013 2015 Open Lookup in New Window Bookmarklet

Since there’s currently no right-click option to open the lookup in a new window, I decided to make a bookmarklet to open the selected lookup in a new window.

Dynamics CRM 2013 2015 Open Lookup in New Window Bookmarklet

Simply click into a lookup field, and then click the bookmarklet to open the record. The script uses the active element; so whichever lookup currently has focus is the one that will be opened.

Dynamics CRM 2013 2015 Open Lookup in New Window Bookmarklet

This works for standard lookups, and also partylists on activities.

The full code for the bookmarklet is below:

javascript:var form=$("iframe").filter(function(){return $(this).css("visibility")=="visible"})[0].contentWindow;var elem=form.document.activeElement;var id=elem.getAttribute("id");var guid=null;var type=null;if(elem.getAttribute("isInlineLookup")=="true"){guid=elem.getAttribute("oid");type=elem.getAttribute("otypename")}else if(id!=null){var pos=id.lastIndexOf("_");if(pos>-1){var suffix=id.substring(pos+1);if(["ledit","lookupDiv","i"].indexOf(suffix)>-1){id=id.substring(0,pos)}id=id.replace("_i_ledit_multi","").replace("_ledit_multi","")}var control=form.Xrm.Page.getControl(id);if(control!=null){var field=control.getAttribute();if(field!=null){var value=field.getValue();if(value!=null){var record=value[value.length-1];guid=record.id;type=record.entityType}}}}if(guid!=null&&guid!=""&&type!=null&&type!=""){var url=form.Xrm.Page.context.getClientUrl()+"/main.aspx?etn="+type+"&id="+guid+"&pagetype=entityrecord";window.open(url)}else{alert("Unable to open record. Make sure you're clicked into a lookup field with a value.")}void(0);