Friday, June 15, 2012

Microsoft Dynamics CRM 2011 Create new case from account's homepage ribbon

Microsoft Dynamics CRM 2011 Create new case from account's homepage ribbon Or cut the clicks

This is a how to create new case from account grid using ribbon button, just like if you would create the case from case sub grid in account form. It gets all the attributes mapping from related account.
The idea behind it was to cut the time for creating new case, Instead of going to account homepage, opening the account form, click on case sub grid and then create the case, It will be just go to account homepage choose the account and create new case.
This is a real time saver.

1) Create new solution.
2) Add new web resource type JavaScript

var CASE_URL = "/main.aspx?etc=112&extraqs=%3f_CreateFromId%3d%257b{ACCOUNTID}%257d%26_CreateFromType%3d1&pagetype=entityrecord";
CreateNewCaseFromAccount = function(id)
                        //get accountid
                        var nakedId = id.replace("{", "").replace("}", "");
                        var caseUrl = CASE_URL.replace("{ACCOUNTID}", nakedId);
                        var caseUrl = Xrm.Page.context.prependOrgName(caseUrl);
3) Add button to account's homepage ribbon to call CreateNewCaseFromAccount function. Two ways for adding the button to account.
1) Use Ribbon workbench.
2) The old fashion way, do it yourself.
a. Add account to solution.
b. Export solution.
c. Extract the solution file.
d. Open customizations.xml using your favorite notepad
e.Add the button to the RibbonDiffXml:

          <CustomAction Id="HomepageGrid.account.MainTab.Actions.CreateNewCase.CustomAction" Location="Mscrm.HomepageGrid.account.MainTab.Actions.Controls._children" Sequence="41">
              <Button Id="HomepageGrid.account.MainTab.Actions.CreateNewCase" Command="HomepageGrid.account.MainTab.Actions.CreateNewCase.Command" Sequence="20" ToolTipTitle="Create New Case" LabelText="Create New Case" ToolTipDescription="Create New Case" TemplateAlias="o1" />
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
          <CommandDefinition Id="HomepageGrid.account.MainTab.Actions.CreateNewCase.Command">
              <EnableRule Id="HomepageGrid.account.MainTab.Actions.CreateNewCase.Command.EnableRule.SelectionCountRule" />
            <DisplayRules />
              <JavaScriptFunction FunctionName="CreateNewCaseFromAccount" Library="$Webresource:new_/CreateNewCase/CreateNewCase.js">
                <CrmParameter Value="FirstSelectedItemId" />
          <TabDisplayRules />
          <DisplayRules />
            <EnableRule Id="HomepageGrid.account.MainTab.Actions.CreateNewCase.Command.EnableRule.SelectionCountRule">
              <SelectionCountRule AppliesTo="SelectedEntity" Maximum="1" Minimum="1" Default="true" />
        <LocLabels />

f. Import the solution back and publish.

Good luck.

This post was written before Dynamics CRM 2011 RU 8 and the new Xrm.utility, It changes only the way of opening new form the basic idea of this post stays the same.
For more information about Xrm.utility go to
or many other posts that explains the new functions available.

No comments:

Post a Comment