Udostępnij za pośrednictwem


Dynamics CRM Entity Ribbon not loading in IFD Environment

Some users have been having this issue in CRM so the blog below will highlight this scenario.

 

Imagine that on the case entity, you have created a custom button on the ribbon “Create New Article”.

If you accessed your CRM Organization using the IFD URL and clicked on the “Create New Article” button out of the context of the case record, then the ribbon bar on the new article form didn’t appear.
If you accessed the Organization using Internal URL then the ribbon got loaded.

Why does this happen?

This happens in situations in which the function responsible for the Create New Article button had following structure:
function CreateNewArticle() {
var serverUrl = Xrm.Page.context.getServerUrl();
var kbarticletemplateId = '{C3F93721-91B6-475A-ACD0-0A68AA1CB842}';
var url = "";
url = serverUrl + "/main.aspx?etn=kbarticle&extraqs=_CreateFromId%3d%26_CreateFromType%3d%26_tmplid=" + kbarticletemplateId + "%26etc%3d127&pagetype=entityrecord";
window.open(url, null, 'width=900,height=750,location=no,toolbar=no,status=yes,resizable=yes', false);
}

 

The cause is that when you use the Xrm.Page.context.getServerUrl() method, this will return following:

1. For IFD, you get following URL format:
https://OrganizationName.DomainName.com/
2. While, when retrieving an Internal URL (http or https) the format is the following:
http(s)://CRMServerName.Domain.Com/OrganizationName

Based on the above, if we access the CRM Organization using the IFD URL then “/main” is appended to the https://OrganizationName.DomainName.com/ and it results in https://OrganizationName.DomainName.com//main and it is failing.

What can we do to solve this problem?

To work around this, you can modify the script to identify which URL we are using. This will check if the URL is for IFD or Internal URL. This is based on the fact that we know that if we access the CRM Organization using the IFD URL, this will contain the OrganizationName right after https://, .We can then extract it and compare with the actual OrganizationName. If they match, then we know that we are accessing CRM via IFD and we need to change the URL accordingly. If they don’t match then we know that we don’t access CRM via IFD and there is no need to change the URL.

The resulting code would be something similar to this. You can find in yellow the most relevant parts of the applied workaround:

function CreateNewArticle() {
var serverUrl = Xrm.Page.context.getServerUrl();
var organizationName = Xrm.Page.context.getOrgUniqueName();
var kbarticletemplateId = '{C3F93721-91B6-475A-ACD0-0A68AA1CB842}';
var url = "";
//We will use the tempServerUrl variable to see if we are accessing the CRM Organization via IFD or via the Internal URL
//when we access the CRM Organization via IFD the URL format is https://CRMOrganizationName.domain.com:
//what we can do to see if we are accessing via IFD or not is to get the CRMOrganizationName from the Url returned by Xrm.Page.context.getServerUrl()
//and compare it to the actual organization name returned by Xrm.Page.context.getOrgUniqueName();
//If they match, then we know that we are accessing the CRM Organization via IFD and not via the Internal URL or via http
var tempServerUrl = "";
//We remove the first 8 characters (https://) from the Server URL so from "https://CRMOrganizationName.domain.com:", we will have "CRMOrganizationName.domain.com:"
//this will not affect the http connection as the http url has 7 characters https:// instead of 8 https://
tempServerUrl = serverUrl.substring(8, serverUrl.length);
//Then we check for the organizationName length and and keep the number of characters from the tempServerUrl matching the number of characters in the organizationName
//so we will have from "CRMOrganizationName.domain.com:" only "CRMOrganizationName"
tempServerUrl = tempServerUrl.substring(0, organizationName.length);
//We set them both to lower case so that we can compare them
tempServerUrl = tempServerUrl.toLowerCase();
organizationName = organizationName.toLowerCase();
//we then compare them.
//if these strings match, then we know we are using IFD and we build the URL accordingly -> we remove the extra '/' which is added by Xrm.Page.context.getServerUrl()
if (tempServerUrl == organizationName) {
serverUrl = serverUrl.substring(0, serverUrl.length - 1);

}
//else we keep the URL untouched.
url = serverUrl + "/main.aspx?etn=kbarticle&extraqs=_CreateFromId%3d%26_CreateFromType%3d%26_tmplid=" + kbarticletemplateId + "%26etc%3d127&pagetype=entityrecord";
window.open(url, null, 'width=900,height=750,location=no,toolbar=no,status=yes,resizable=yes', false);
}

 

Best Regards

EMEA Dynamics CRM Support Team

 

Share this Blog Article on Twitter

Tweet

Follow Us on Twitter

Follow @MSDynCRMSupport