Archive for August, 2015

Microsoft Dynamics CRM 2013/2015 Custom Alerts and Popup Dialogs JavaScript Lightbox

August 24, 2015



This JavaScript library for CRM 2013 and CRM 2015 allows us to create custom popup alerts in CRM forms and views.

CRM 2013 introduced light-boxes for most popups to make the UI look cleaner with less browser alerts and popups. However, these internal functions were not included in the SDK, so as developers we couldn’t access them for our custom code. Instead, we’ve been forced to use alertDialog and confirmDialog which under the hood just calls the browsers alert and confirm functions.

The main problems with this is that we cannot customize the buttons, and the alerts look ugly.

Using this library we can now hook into those internal functions allowing us to create our own seamless alerts and popups using custom buttons and custom callback functions for each button. We can also specify different types of icons to display in the alerts, instead of being forced to use the alert ‘exclamation mark’ or confirm ‘question mark’.

While technically unsupported, this code is manageable if it ever does break in future CRM releases, so it will be as simple as updating the solution files and everything will just work. In the event that the CRM Lightbox doesn’t work or isn’t supported (like in outlook), a modalDialog will be displayed.

How it Works

Download and install the unmanaged solution, then simply add a reference to mag_/js/alert.js wherever you want to use the custom alerts. This will work from forms, views, command bars, and pretty much anywhere in CRM that supports JavaScript.

Next simply call the function. All other dependent web resources will be loaded automatically.

Parameters: Title (main message), Subtitle (smaller message), Buttons (array), Icon, Width (px), Height (px), CRM Base URL

All the parameters are technically optional. If no buttons are specified, a default ‘OK’ button with no callback will be added. If no icon is specified, then no icon will be displayed. If height is not specified, it will default to 225. If width is not specified it will default to 450. The URL only needs to be specified if the alert is being called from somewhere that doesn’t have Xrm.Page access (e.g. web resource).

Each button object in the buttons array needs to have a ‘label’ (text displayed on the button), and optionally a ‘callback’ (function called if the button is clicked).

The following icons are supported: “INFO”, “WARNING”, “ERROR”, “SUCCESS”, “QUESTION”."Would you like to create a new Sale?", null,
        label: "Create Sale",
        callback: function () {
  "Sale created successfully!", null, null, "SUCCESS", 500, 200);
        label: "Not now"
    }], "QUESTION", 500, 200);



Microsoft CRM 2013/2015 Custom Notifications in JavaScript

August 17, 2015



This library gives developers the ability to create nice CRM notifications on forms and views, similar to the Xrm.Page.ui.setFormNotification SDK function, but better!

It gives us all the same functionality as the setFormNotification SDK function, but has the following additional features:

  • Allows you to add buttons and/or hyperlinks into the notification, with custom JavaScript triggered on click.
  • Supports additional icons, including SUCCESS, QUESTION, and LOADING
  • Supports custom HTML tags to be used manually in the notification message for greater flexibility
  • Ability to manually close a notification using the ‘X’ on the right hand side
  • Has smooth slide in and out transitions when adding and removing notifications
  • Ability to specify a duration after which that particular notification will disappear
  • Supports displaying notifications inside views from command bar buttons (only in web client – must specify duration)


Add Notification

Adds or overwrites a notification on the custom notification bar. Note that this notification bar is separate to the CRM Notification bar.

Parameters: Message, Icon, Unique ID, Buttons (array), Duration (seconds – optional)

All parameters are technically optional, if there’s no icon specified the icon will be removed, if the unique ID is not specified, the ID will be null (and any new notifications with no ID will overwrite that one), the buttons are optional and will display after the message in the order they are added to the array, duration is optional, and if not specified the notification will only disappear if the user manually dismisses it or if other code removes it.

Supported Icon types are: “INFO”, “WARNING”, “ERROR”, “SUCCESS”, “QUESTION”, “LOADING”

Each button object in the array should have a ‘text’ to display on the button or hyperlink, a ‘callback’ function to call when the button or hyperlink is clicked, and optionally a ‘type’ of ‘link’ or ‘button’ (defaults to button if not specified)

Notify.add("Would you like to create a new <b>Sale</b>?", "QUESTION", "sale",
        type: "button",
        text: "Create Sale",
        callback: function () {
            Notify.add("Sale created successfully!", "SUCCESS", "sale", null, 3);
        type: "link",
        text: "Not now",
        callback: function () {


Remove Notification

Removes one or all notifications from the custom notification bar. If an ID of a notification is passed to this function, that notification will be removed. If no ID is passed to this function, all notifications will be removed.

Parameters: Unique ID (optional)

// Remove a single notification


// Remove all notifications


Microsoft Dynamics CRM 2013/2015 Call Action, Workflow, or Dialog from JavaScript

August 10, 2015


This simple JavaScript library allows you to easily call workflows, dialogs, and actions in CRM from forms, views, web resources, or anywhere that supports JavaScript.

In the past if you’ve needed to call a workflow or action from JavaScript, you need to build a massive XML SOAP request making sure to pass in the correct attributes and conditions to get the request working.

This is tedious and messy, especially when there are many places you need to do this in a solution. It’s also not good if something breaks in the future and you need to go back and fix up all instances of where the code is being used.

For these reasons, I’ve created this library to simplify calling processes, and to make the code manageable going forward. But most of all, it’s so I don’t have to keep finding the correct way to build the SOAP requests!

For completeness, I’ve also included a function for calling dialogs, which simply pops open the specified dialog.

Call Workflow

Runs the specified workflow for a particular record asynchronously. Optionally, you can add callback functions which will fire when the workflow has been executed successfully or if it fails.

Parameters: Workflow ID/Guid, Record ID/Guid, Success Callback (function), Error Callback (function), CRM Base URL (not required on forms/views)


    function () {
        alert("Workflow executed successfully");
    function () {
        alert("Error executing workflow");

Call Action

Calls the specified action and returns the response from the action asynchronously. Useful when needing to run C# code from web resources or command bar buttons when only JavaScript is available.

Parameters: Action Unique Name, Input Parameters (array), Success Callback (function), Error Callback (function), CRM Base URL (not required on forms/views)

Each Input Parameter object should contain key, value, and type. Types are defined by Process.Type enum. EntityReference values should be an object containing id and entityType.

The Success Callback function should accept 1 argument which is an array of output parameters, each containing key, and value


        key: "Target",
        type: Process.Type.EntityReference,
        value: { id:, entityType: "lead" }
    function (params) {
        // Success
        for (var i = 0; i < params.length; i++) {
            alert(params[i].key + "=" + params[i].value);
    function (e) {
        // Error

Call Dialog

Opens the specified dialog for a particular record in a CRM light-box, or Modal Dialog if run from Outlook. Once the dialog is closed, the form or view is refreshed to display any new data changed by the dialog.

Parameters: Dialog ID/Guid, Entity Name, Record ID/Guid, CRM Base URL (not required on forms/views)


Process.callDialog("C50B3473-F346-429F-8AC7-17CCB1CA45BC", "contact",,         
    function () {; 


Multiselect for Microsoft Dynamics CRM

August 7, 2015

Supported way for multiple value selection in Dynamics CRM.
Tested on Dynamics CRM 2013, CRM 2015.