Saturday, May 30, 2009

CRM 4.0 Finding Entity URL

This is a small trick you can use to find what URL is stored behind each CRM vanilla (customizable) entity. You can use as part of your code (see my post about cloning an entity using JavaScript) or just run it in IE address bar. Although it seems this function is not going anywhere there is a chance it won’t be there on the next version.

Address bar function:
javascript:void( alert( getObjUrl( 2 ) ) )


The getObjUrl function utilizes the GetWindowInformation function which receives the entity object type code e.g. 2 – contact and return an object containing the entity Url and window size (width and height). Here is an example of how to use it inside your code:

var contactUrlInfo = GetWindowInformation(2);
var windowFeatures = “height=” + contactUrlInfo.Height + “,width=” + contactUrlInfo.Width + “,toolbars=0”;
window.open( prependOrgName( contactUrlInfo.Url ) , “contact window” , windowFeatures );


So how does this work?
The GetWindowInformation function refers to “/_common/windowinformation/windowinformation.aspx” URL. If you open this page in the address bar and take a look at the page source you’ll see a script that look like this:


function CRMWindowInfo(sUrl, iXOffset, iYOffset)
{
this.Width = parseInt(iXOffset, 10);
this.Height = parseInt(iYOffset, 10);
this.Url = sUrl;
}
function GetWindowInformation(iObjectType) {
switch (parseInt(iObjectType, 10))
{
case Account: return new CRMWindowInfo("sfa/accts/edit.aspx",1000,560);
case List: return new CRMWindowInfo("ma/lists/edit.aspx",820,560);
//and so on…
}
}


In order not to rely on ms functionality you can either work with static values or create your own page under the isv folder the returns similar js.

No comments: