Wednesday, November 6, 2013

How to restore a hidden button on the CRM 2013 Command Bar

The new Dynamics CRM 2013’s command bar has deliberatly limited space for buttons due to the ‘intentionally constrained’ user interface design. The idea being that if you limit the space for buttons, then designers will be forced to only show those that are absolutely necessary and the user experience will be improved. As result, many of the buttons from the CRM 2011 Ribbon Bar have been removed from the CRM 2013 Command Bar.
The CRM2011 Ribbon Buttons are still there, but hidden using a new RibbonXml Display Rule named 'Mscrm.HideOnCommandBar'. This article shows you how to restore those buttons to the Command Bar that your users absolutely must have using the Ribbon Workbench for CRM2013.
1. Create a solution containing the entities that you wish to restore buttons for. This example uses the ‘Case’ entity, and we are restoring the ‘Connect’ button on the ‘Form’ command bar.
Before customising, the Form Command Bar looks like the following:
You’ll notice that only 5 buttons are shown until buttons are added to the ‘overflow’ menu. The ‘Connect’ button is not here since it was deemed unessential.
2. Open the solution containing the Case entity in the Ribbon Workbench for CRM 2013 and select the ‘incident’ entity if not already selected. You will see by default the Command Bar is selected.
 
3. In order to locate the button we want to restore, click on the ‘Ribbon’ selector to show the Ribbon. This will show the Ribbon Design surface.
4. Select the ‘Form’ ribbon using the dropdown on the top right of the design surface, then select the ‘Connect’ button and Right-Click ‘Customize Command’
5. Locate the Customised Command in the ‘Solution Elements’ tab under ‘Commands’
6.  In the Edit Display Rules dialog, select the ‘Mscrm.HideOnCommandBar’ rule and click the ‘<Remove’ button.
7.  Important: Locate the following Display Rules, and set the ‘IsCore’ property to ‘True’ – this will prevent them from being customised as well:
a.      Mscrm.HideOnCommandBar
b.      Mscrm.CreateConnection
c.      Mscrm.IsConnectionsEnabledPrimary
d.      Mscrm.HideOnModern
8. Important: Locate the ‘Mscrm.FormStateExistingOrReadOnlyOrDisabled’ Enable Rule, and set the ‘IsCore’ property to ‘True’
9. Click ‘Publish’
10 Now when you refresh the Case Form, you will see the Connect button again.
11  You’ll notice that only the default button is shown – so if you use the drop down, you’ll only get the ‘Connect to Another’ option. To enable the ‘To Me’ button repeat the process for the ‘To Me’ button:
Remember to make sure that only the buttons that are really needed are included - the Command Bar has been constrained intentially to give your users the best experience.

Thursday, October 17, 2013

CRM 2013 NEW FEATURES: JAVASCRIPT NOTIFICATIONS

RM 2013 come with a set of new JavaScript functions that we can use for sending notifications to the user.  There are form notifications and field notifications.  Here’s an example of a form notification at work…
The function below was registered on the OnSave event of my form.   It notifies the user that a Save has occurred and timestamps the notification.  I post 3 notifications to demonstrate the 3 different types available (error, warning and information):
function NotifyOnSave() {
    var today = new Date();
    Xrm.Page.ui.setFormNotification('Error! A Save occured at ' + today, 'ERROR');
    Xrm.Page.ui.setFormNotification('Warning! A Save occured at ' + today, 'WARNING');
    Xrm.Page.ui.setFormNotification('Information: A Save occured at ' + today, 'INFORMATION');
}
Here’s what appears after the Save:

It’s a little hard to tell on the screenshot but what has happened is each of those 3 notifications has been posted a second time to the form (note: the UI only shows 3 rows of notification, the user has to scroll down to see the other 6 notifications).  The Information notification appears twice due to the sort order applied by the UI:  Information notifications first, then Error notifications followed by Warning notifications.   This is the default behavior  of setFormNotification().   We have options though, we can assign each notification a unique ID and then we can overwrite a previous notification and avoid duplication in a scenario like this.  Here’s the revised JavaScript (note the unique ID added as a 3rd parameter):
function NotifyOnSave() {
    var today = new Date();
    Xrm.Page.ui.setFormNotification('Error! A Save occured at ' + today,'ERROR','1');
    Xrm.Page.ui.setFormNotification('Warning! A Save occured at ' + today,'WARNING','2');
    Xrm.Page.ui.setFormNotification('Information: A Save occured at ' + today,'INFORMATION','3');
}

If you want to clear a notification you use clearFormNotification() and you identify the notification by its unique ID:
    Xrm.Page.ui.clearFormNotification('1'); 

We also get field notification in CRM 2013.  The syntax for these is:
Xrm.Page.getControl(fieldName).setNotification(message);


Tuesday, July 30, 2013

Change the header color of form using Javascript.

InjectHeaderCSS("00C78C","F6F8FA");

function InjectHeaderCSS(startColor, endColor) {

var headerCSSIE9 = ".ms-crm-Form-HeaderContainer{ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#" + startColor + ", endColorstr=#" + endColor + "); }";
var headerCSSIE10 = ".ms-crm-Form-HeaderContainer{background: -ms-linear-gradient(top,  #2989d8 0%,#" + startColor + " 0%,#F6F8FA 100%,#" + endColor + " 100%);}";

var headerchrome = ".ms-crm-Form-HeaderContainer{background: -webkit-linear-gradient(top,  #2989d8 0%,#" + startColor + " 0%,#F6F8FA 100%,#" + endColor + " 100%);}"

var head = document.getElementsByTagName('head')[0];
var styleElement = document.createElement('style');
styleElement.setAttribute('type', 'text/css');
if (styleElement.styleSheet) {
    if (Mscrm.Utilities.isIE9()) {
        styleElement.styleSheet.cssText = headerCSSIE9;
    } else if (Mscrm.Utilities.isIE10()) {
        styleElement.styleSheet.cssText = headerCSSIE10;
    } else if (Mscrm.Utilities.isChrome()) {
        styleElement.styleSheet.cssText = headerchrome;
    } else {
        styleElement.styleSheet.cssText = headerCSSIE9;
    }
}
else {

    if (Mscrm.Utilities.isIE9()) {
        styleElement.appendChild(document.createTextNode(headerCSSIE9));
    } else if (Mscrm.Utilities.isIE10()) {
        styleElement.appendChild(document.createTextNode(headerCSSIE10));
    } else if (Mscrm.Utilities.isChrome()) {
        styleElement.appendChild(document.createTextNode(headerchrome));
    } else {
        styleElement.appendChild(document.createTextNode(headerCSSIE9));
    }
}
head.appendChild(styleElement);

 }

Monday, July 29, 2013

Default Activity ‘Filter on’ to ‘All’ Dynamics CRM 2011 UR12

//default the Activities 'Filter on' to 'All' for Account and Contact for rollup 12 

function filterAllActivities() {

    document.getElementById("navActivities").onclick = function () {
        Mscrm.Details.loadArea(this, "areaActivities");
        document.getElementById("areaActivitiesFrame").onload = function () {
            var entityName = Xrm.Page.data.entity.getEntityName();
            var entity = entityName.charAt(0).toUpperCase() + entityName.substr(1);
            var doc = this.contentWindow.document;
            var filterOn = doc.getElementById("crmGrid_" + entity + "_ActivityPointers_datefilter");
            filterOn.value = "All";
            var evt = document.createEvent("HTMLEvents");
            evt.initEvent("change", false, true);
            filterOn.dispatchEvent(evt);
        };
    };
}

Monday, July 1, 2013

How to get FetchXml of Advance Find View?

    var advFind = _mainWindow.$find("advFind"),
    iOldMode = advFind.get_fetchMode();
    advFind.set_fetchMode(Mscrm.FetchModes.ignoreEmpty);
    var sFetchXml = advFind.get_fetchXml();

Monday, May 27, 2013

Opening Forms using the Xrm.Utility.openEntityForm



Using the openEntityForm

Opening a New Form

To simply open a form for creating a new record you can use the following line of code. Simply replace account with the entity of your choice.

Xrm.Utility.openEntityForm("account");

Open a Form with an Existing Record

If you want to open a specific record you just add the guid for that record like this:

Xrm.Utility.openEntityForm("account","A85C0252-DF8B-E111-997C-00155D8A8410″);