Today I encountered a strange issue while working with CRM 2011. So, I have made a Web Resource containing an html file. Basically, what the html file does is call a URL to display the “Create” version of the entity’s form. And that web resource is embedded in a dashboard.
window.location.href = “/main.aspx?etn=new_entity&extraqs=%3fetn%3dnew_entity&pagetype=entityrecord“;
So, part of the dashboard actually displays the create form of an entity. Fair enough. This worked fine during development, but after importing the solution on another on-premise crm instance, instead of seeing my form, I received the error “The entity with a name “new_entity” was not found in the metadatacache”.
Strange. I searched the web a little, did an iisreset, nothing. After starting the CRM server trace though, I could see that the error was correctly logged, but realized that the organization guid mentioned for the error was another organization’s guid installed on the same server!
So I thought Internet Explorer was messing things up a little with this one. Then I ran a test, setting the absolute URL actually made the thing work! Ok, but then my solution becomes dependent on this organization…
var a = window.location.href; // Just for readibility
var sub1 = a.substring(a.indexOf(‘//’) + 2);
var sub2 = sub1.substring(sub1.indexOf(‘/’) + 1);
var org = sub2.substring(0, sub2.indexOf(‘/’));
This gives the name of the organization present in the URL, without any slash. Included in my original script:
window.location.href = “/” + org + “/main.aspx?etn=new_entity&extraqs=%3fetn%3dnew_entity&pagetype=entityrecord“;
That was it! Probably not my most glorious coding moment, but still worth sharing I think.