Debug a CRM Plug-in using the Plug-in Profiler

Debugging CRM Plugins is no longer difficult with Plug-in Profiler. Follow the steps below and try to debug a CRM plugin in your environment.

1.Build the Plug-in Registration tool according to the instructions in its Readme file. The tool can be found in the Tools\PluginRegistration folder of the SDK download.

Current version of the SDK is 5.0.10

2.Run the Plug-in Registration tool.
Run the Visual Studio solution of plugin registration tool or after build the solution, Run the “PluginRegistration.exe” under “\tools\pluginregistration\bin\Debug\” folder

3.Connect to a Microsoft Dynamics CRM server and organization. For more information on connecting to a server and organization, refer to the SDK topic: Walkthrough: Register a Plug-in Using the Plug-in Registration Tool.

4.Register a plug-in and step on the Microsoft Dynamics CRM server. Keep a copy of the debug compiled plug-in assembly on the computer where you are running the tool.
Although Released or Debug assembly has been registered with the PluginRegistration tool, here it needs Debug Compiled vesion of the assembly to be debug using plugin profiler.

5.In the tool’s main window, select Install Profiler. You will now see a Plug-in Profiler node in the list.


Continue reading “Debug a CRM Plug-in using the Plug-in Profiler”

Advertisement

CRM Manipulation Library

Very useful set of String manipulations, Date manipulations, Calculations, RegEx and Web functions which are not coming as CRM2011 OOB features are included in the manipulation Libray. In another words it is a set of custom workflow activities which can be used with crm workflows and dialogs as well.

Installation Manipulation Library comes as a CRM solution and as a solution of Visual Studio. There are two ways of installing it and use in CRM.

CRM Solution import

CRM solution can be imported to the CRM and after publishing it, the features will be available to use in processes. Thats the easiest way of installing it and if some one needs an unmanaged solution, they can export it as an unmanaged  solution and simply use it in any CRM environment.

Solution Import

Continue reading “CRM Manipulation Library”

CRM Installation Error : Sql instance name must be the same as computer name

When the Sql server instance is differ from the machine name, this error will be given as a result of verification tasks under the system check of CRM installation. Most of the time this happens if the Sql server instance changes after the first installation and reinstallations.

CRM Installation Sql Error
CRM Installation Error

Anyhow this can be fixed easily as we can use few sql stored procedures. Follow the steps listed below.

Continue reading “CRM Installation Error : Sql instance name must be the same as computer name”

Plugin Deployment Options – Dynamics CRM

The 3 storage options are: Database, Disk and GAC. The main differences between these are:

Database: The assembly dll is stored in the database, rather than the file system. The major advantages are that the assembly need only be deployed once multiple CRM servers are available, and that no additional action is required to restore / redeploy the assembly either during disaster recovery, or if redeploying to an alternate server. This is the preferred option in a production environment

Disk: The assembly dll is placed in the \server\bin\assembly directory on each server. Have to ensure the dll is placed in the correct place on all CRM servers, so the deployment overhead is a little greater. Better to use this option in development environments as the developer can redeploy newer versions solely by file transfer, rather than reregistering. Also, if debugging, the assembly .pdb file needs to be placed in the same location; with this option it’s easy to ensure the dll and pdb are from the same build

GAC: The assembly is placed in the Global Assembly Cache on each CRM server, and again will have to do this. The GAC does allow multiple versions of an assembly, but CRM doesn’t, so don’t really gain anything by using the GAC.

According to my experience deploying the plugin assemblies to the Database is the best option as we can backup and restore the databases and minimizing assemblies deployments and other setting changes.

Set Server Url to OData Query Dynamically using JavaScripts in CRM 2011 Forms

Following statement can be used to retrieve accounts from the CRM application with the MyOrganization hosted in DevServer.

http://DevServer/MyOrganisation/xrmservices/2011/OrganizationData.svc/AccountSet?$select=swmship_FirstName,swmship_Surname&$filter=startswith(Address1_City,’Ca’)

http://DevServer/MyOrganisation/” part is varried according to the hosted server and the organization and it might raise errors when the above OData query get executed in some other CRM application.

Following JavaScript can be used to get the server url in the CRM 2011 forms.

var serverUrl = Xrm.Page.context.getServerUrl();

Get the next part of the OData service part.

var GlobalODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc/";

Continue reading “Set Server Url to OData Query Dynamically using JavaScripts in CRM 2011 Forms”

Application Pool Recycling instead of Restarting IIS – CRM App Pool

Restarting or stopping IIS, or rebooting the Web server, is a server action. When restarting the Internet service, all sessions connected to the Web server (including Internet, FTP, SMTP, and NNTP) are dropped. Any data held in Web applications is lost. All Internet sites are unavailable until Internet services are restarted. For this reason, we should avoid restarting, stopping, or reboot the server if at all possible. IIS 6.0 includes application pool recycling and several other features that provide alternatives to restarting IIS. For a list of features designed to improve IIS reliability and remedy the need to restart IIS.

Restarting IIS (IIS 6.0)

All of the Internet services listed below, if installed, are affected when restarting IIS

Service Description
IIS Admin service This service manages all the services of IIS other than the WWW service (FTP, NMTP, and SMTP).
WWW service This service provides Web connectivity between clients and Web sites.
HTTP SSL service This service provides secure Web connectivity between clients and Web sites.
FTP service This service provides FTP connectivity and administration through IIS Manager.
SMTP service This service transports electronic mail across the network.
NNTP service This service transports network news across the network.

Internet Information Services (IIS) can be configured to periodically restart worker processes assigned to an application pool, which recycles faulty Web applications. Following example shows how to do it manually or using a batch file in a CRM environment.

Continue reading “Application Pool Recycling instead of Restarting IIS – CRM App Pool”

Useful Javascripts for CRM 2011


// Get the form type
GetFormType: function () {
 var FORM_TYPE_CREATE = 1;
 var FORM_TYPE_UPDATE = 2;
 var FORM_TYPE_READ_ONLY = 3;
 var FORM_TYPE_DISABLED = 4;
 var FORM_TYPE_QUICK_CREATE = 5;
 var FORM_TYPE_BULK_EDIT = 6;

 var formType = Xrm.Page.ui.getFormType();
 if (formType == FORM_TYPE_CREATE) {
  alert("This record has not yet been created.");
 }
 else {
  alert("This record exists in the database.");
 }
}




// Registering an event for a custom control, and call a method when it fires
RegisterEventForACustomControl: function (var controlId) {
        var customField = document.getElementById(controlId);
        /* Build Toggle Function */
        var f = "var ef=function() { " +
                  "MethodToBeCalled();" +
                  " };";
        eval(f);
        /* Attach to click event */
        customField.attachEvent('onclick', ef, false);
}

MethodToBeCalled: function () {
        // Do something
}




// Disable/Enable all controls in a Tab
DisableAllControlsInTab: function (tabName, isDisable) {
    var tabControl = Xrm.Page.ui.tabs.get(tabName);
    if (tabControl != null) {
        Xrm.Page.ui.controls.forEach(
        function (control, index) {
            if (control.getParent().getParent() == tabControl && control.getControlType() != "subgrid") {
                control.setDisabled(isDisable);
            }
        });
    }
}




// Get the value from a CRM field
var varMyValue = Xrm.Page.getAttribute("CRMFieldSchemaName”).getValue() ;

// Set the value of a CRM field
Xrm.Page.getAttribute("CRMFieldSchemaName”).setValue(‘New Value’);




// Hide/Show a tab using 
Xrm.Page.ui.tabs.get("CRMTabName").setVisible(true);
Xrm.Page.ui.tabs.get("CRMTabName").setVisible(false);

Xrm.Page.ui.tabs.get(5).SetVisible(false);
Xrm.Page.ui.tabs.get(5).SetVisible(true);




// Hide/Show a section in a tab
Xrm.Page.ui.tabs.get("CrmTabName").sections.get("SectionName").setVisible(true);
Xrm.Page.ui.tabs.get("CrmTabName").sections.get("SectionName").setVisible(false);




// Call the onchange event of a field
Xrm.Page.getAttribute("CRMFieldSchemaName”).fireOnChange();




// Get the selected value of picklist
Xrm.Page.getAttribute("CRMFieldSchemaName”).getSelectedOption().getValue();




// Set the requirement level
Xrm.Page.getAttribute("CRMFieldSchemaName”).setRequiredLevel("none”);
Xrm.Page.getAttribute("CRMFieldSchemaName”).setRequiredLevel("required”);
Xrm.Page.getAttribute("CRMFieldSchemaName”).setRequiredLevel("recommended”);




// Set the focus to a field
Xrm.Page.getControl("CRMFieldSchemaName”).setFocus(true);




// Return array of strings of users security role GUIDs:
Xrm.Page.context.getUserRoles()




// Setting Force Submit to the field, This must be set to save the data
Xrm.Page.getAttribute("CRMFieldSchemaName”).setSubmitMode("always”);




// Stop an on save event
event.returnValue = false;




// Form close
Xrm.Page.ui.close();


Microsoft Dynamics CRM 2011 – Hide Areas of a Form

// Toggle the Ribbon Toolbar to Show/Hide (same as clicking the show/hide Ribbon button)
window.top.document.getElementById("minimizeribbon").fireEvent("onclick");

// Hide the Ribbon Toolbar and move the form Content area to the top of the window.
window.top.document.getElementById("crmTopBar").style.display = "none";
window.top.document.getElementById("crmContentPanel").style.top = "0px"; // Move Form Content area up to top of window, initial style.top is 135px

// Hide Left Hand Nav bar / pane
document.getElementById("crmNavBar").parentElement.style.display = "none";
document.getElementById("tdAreas").parentElement.parentElement.parentElement.parentElement.colSpan = 2;

// Hide the Breadcrumb and Record Set Toolbar
document.getElementById("recordSetToolBar").parentElement.style.display = "none";

// Hide the Form Footer Bar
document.getElementById("crmFormFooter").parentElement.style.display = "none";

Get the CRM server url from Silverlight [If the silverlight page is in a form]

private static String GetServerUrlFromCrmContext()
{
    try
    {
        // If the Silverlight is in a form, this will get the server url
        ScriptObject xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
        if (xrm != null)
        {
            ScriptObject page = (ScriptObject)xrm.GetProperty("Page");
            ScriptObject pageContext = (ScriptObject)page.GetProperty("context");

            String serverUrl = (String)pageContext.Invoke("getServerUrl");
            return serverUrl;
        }
        else
        {
            goto DevUrl;
        }
    }
    catch
    {
        goto DevUrl;
    }

    DevUrl:
    return "http://10.100.4.100:5555/MyOrganization";
}

Reference an Image Web Resource from Site Map SubArea

Adding an image to the site map can be done by two ways.

  1. Giving a image path from the icon folder
  2. Giving a path from the web resources

Giving a path from the web resources is very effective in CRM 2011, as web resources are always reside with CRM Solutions. Follow the steps given below to add an image from web resources.

  • Upload the image as a web resource to the solution. (E.g. swcmt_CommitteesSiteMapIcon24x24)

  • Publish the solution and export the un-managed solution.
  • Extract the zip file and open the “customizations.xml” file from the Visual Studio (or any other xml editor).
  • Find the “<Area>” tag that the new image needed.
  • Modify the xml as follows;

<Area Id="SWCmt" ResourceId="Area_Committee" Title="Committees" ShowGroups="true" Icon=”$webresource:swcmt_CommitteesSiteMapIcon24x24″ DescriptionResourceId=”Committee_Description”>

      
It shows in the CRM application as follows;