Referencing Multiple Javascript Libraries in Homepage Ribbon Buttons
When we develop JavaScript functions for the Actions and CustomRules of the Ribbon buttons in CRM 2011, we may need to reference the common JavaScript library or other javascript libraries. For the ribbon buttons on the form, we can simply add those additional libraries in the Form Libraries and call the functions in those libraries but for Homepage ribbon buttons, we need to try a different approach to achieve it.
The FunctionName of the JavaScriptFunction action tag is required so that putting isNaN as a value will do the trick instead of calling the dummy function with no action.
This method can also be used for Sub-grid ribbon buttons if the sub-grid is displayed is multiple forms and adding those common libraries in all those forms is a tedious job.
Another way of doing this is to load another JavaScript webresource by calling the following JavaScript function and passing the name of the web resource.
e.g.
LoadWebResource("new_commonlibrary.js");
<Actions>
<JavaScriptFunction Library="$webresource:new_MainEntityLibrary" FunctionName="Test" />
<JavaScriptFunction Library="$webresource:new_CommonLibrary" FunctionName="isNaN" /> //This is the additional library
</Actions>
The FunctionName of the JavaScriptFunction action tag is required so that putting isNaN as a value will do the trick instead of calling the dummy function with no action.
This method can also be used for Sub-grid ribbon buttons if the sub-grid is displayed is multiple forms and adding those common libraries in all those forms is a tedious job.
Another way of doing this is to load another JavaScript webresource by calling the following JavaScript function and passing the name of the web resource.
e.g.
LoadWebResource("new_commonlibrary.js");
LoadWebResource = function(resourceName)
{
var httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
httpRequest.open("GET", "/" + ORG_UNIQUE_NAME + "/webresources/" + resourceName, false);
httpRequest.send(null);
try
{
eval(httpRequest.responseText);
}
catch (e)
{
alert("Error loading " + resource + ":\n" + e.description);
}
}
The use of ActiveXObject("Msxml2.XMLHTTP") is sadly not supported by Chrome or Firefox. It only works for IE.
ReplyDeleteAnyone know a workaround for the other browsers?