Monday, June 25, 2012

Microsoft Dynamics CRM 2011 Running javascript on IE F12 developer tools

Microsoft Dynamics CRM 2011 Running javascript on IE F12 developer tool

This way it is possible to check javascript in run time on the form.

1) Open some form in the crm.
2) Press F12 -> Open the IE F12 developer tools
3) Open script tab
3) type
Xrm = document.frames["contentIFrame"].Xrm; 
Xrm = frames[0].Xrm
4) Run your code

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.

Thursday, June 14, 2012

Dynamics CRM 2011 readonly form javascript

Dynamics CRM 2011 read-only form JavaScript.

With it does:
1)     Hides the content of a form with transparent div.
1)     Easier way to disable all the controls of the form and enabling them while keeping all the logic of the form (pre disabled controls will keep be disabled).
2)     It's faster than going over all the controls and disabling them.
1)     Partially Unsupported

How to guide:
1)     Create new JavaScript web resource
2)     Add this code:
            //Disable all form controls
            DisableForm = function() {
                        var iframeDoc = document;
                        var iframeBody = document.getElementById("crmFormTabContainer");
                        hideContent(iframeDoc, iframeBody);
                                    function(tab, index)
                                                            var iframeDoc = document;
                                                            var iframeBody = document.getElementById("crmFormTabContainer");
                                                            var roSpan = document.getElementById("readonlySpan");
                                                            if (roSpan != null) {
                                                            hideContent(iframeDoc, iframeBody);

            hideContent = function(htmlDocument, htmlElement) {
                        var roSpan = htmlDocument.createElement("div");
               = "readonlySpan";
                        var roStyle = "position:absolute;";
                        roStyle += "z-index:1;";
                        roStyle += "left:0px;";
                        roStyle += "top:0px;";
                        roStyle += "height:"+htmlElement.scrollHeight+"px;";
                        roStyle += "text-align:center;";
                        roStyle += "font:72px Tahoma;";
                        roStyle += "opacity:0.20;";
                        roStyle += "-moz-opacity:0.20;";
                        roStyle += '-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)";';
                        roStyle += 'filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)"';
                        roStyle += "filter: alpha(opacity=20);";
                        roStyle += "background-color:white;";

               = roStyle;
                        roSpan.innerHTML = "<div style='margin-top:30%;height:100px;'>READ ONLY</div>";
               = 1;
            //Enable all form control keep readonly / disable logic.
            EnableForm = function() {
                        var iframeBody = document.getElementById("crmFormTabContainer");
                        var roSpan = document.getElementById("readonlySpan");
                        if (roSpan != null) {
3)     Add DisableForm function to onload event of the form.

**Another way to disable all the controls

Good luck.