jump to navigation

CRM 2011: Load javascript libraries in custom ribbon button April 14, 2012

Posted by hvdeath in CRM 2011, Ribbon.
Tags: , , ,

If you’d like to create a little bit more complex ribbon button you need to load more javascript libraries for a single button event handler. For example if we have to create a button which update the selected item in the grid based on some business logic, and we don’t want to invoke web service endpoint directly, we can create a CommandDefinition that use CRM 2011 REST SDK library for update entity. (For create a simple ribbon button check Walkthrough: Add a Custom Button to an Existing Group for a Specific Entity)

For that functionality we need to load our event handler javascript with sdk.rest.js and json2.js too. To load javascript libraries first we need to upload to a Web Resource. Than we can reference this javascript library in the commanddefinition Actions section as JavaScriptFunction:

<JavaScriptFunction Library="$webresource:new_json2.js" FunctionName="isNaN" />

<JavaScriptFunction Library="$webresource:new_sdk.rest.js" FunctionName="isNaN" />

The important part is to set isNaN for FunctionName attribute! Then you can use libarary functions in your event handler script. So for example the CommandDefinition is look like:

<CommandDefinition Id="Mscrm.UpdateSelectedRecord">
 <EnableRule Id="Mscrm.Enabled"/>
 <EnableRule Id="Mscrm.SelectionCountExactlyOne"/>



<JavaScriptFunction Library="$webresource:new_json2.js" FunctionName="isNaN" />

<JavaScriptFunction Library="$webresource:new_sdk.rest.js" FunctionName="isNaN" />

<JavaScriptFunction Library="$webresource:new_task_formscripts.js" FunctionName="Task_Update">

<CrmParameter Value="FirstSelectedItemId"/>




In the button event handler function you can use that libraries:

function Task_Update(taskId) {
var task = {};
task.New_ismarked = true;

//update task
function () {
auto(4212); //refresh grid for task entity (task's ObjectID is 4212)
function (error) {
alert("There was an error during task update:" + error.message);

That’s all!



1. Destiphy - August 28, 2012

As I met some side-effects with dynamically loading scripts in JS i searched for a workaround, i also thought about how could i load these other needed libs – maybe “directly” in ribbon … well, 10 seconds before i started to try it on my own, I found this article, thx, saved me some time :))

-You can also use this “RibbonJSLoading” when you define an EnableRule 😉

Greets, Destiphy

2. forex Signals Service - March 14, 2013

Pretty! This has been an incredibly wonderful article.
Many thanks for supplying these details.

3. Mitch Milam's xRM Discussions » Dynamics CRM 2013 SDK 6.0.2 Released - December 13, 2013
4. CRM 2011: Add javascript library to ribbon button - Dowawado – About Microsoft - March 1, 2014

[…] I found here, what you need to do is, in the command of the button click, using ribbon workbench for example (or […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: