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

private static String GetServerUrlFromCrmContext()
        // 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;
            goto DevUrl;
        goto DevUrl;

    return "";

Register all Assemblies in GAC at once

GACUTIL is the tool available to register assemblies to the GAC.
Eg.g gacutil.exe /i C:\MyAssemblies\test1.dll
But if there are more than one assemblies to be registered, use following in the command prompt
FOR %a IN (C:\MyAssemblies\*.dll) DO GACUTIL /i %a

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;

dtexec Utility (SSIS Tool)

You can run dtsx (SSIS Package) files in powershell using this tool.

EXEC xp_cmdshell ‘dtexec /f “C:\DATA\EligibilityCategory.dtsx”‘
The following example shows how to run the same package and capture the return code:

DECLARE @returncode int
EXEC @returncode = xp_cmdshell ‘dtexec /f “C:\DATA\EligibilityCategory.dtsx”‘

Following values will be returned;

Find public key token for a .NET DLL or assembly

You can get the public key token by using following command. Keep in mind that the dll should be a “Strongly Typed” one.

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>sn -T C:\sdk\Microsoft.Xr

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Public key token is 31bf3856ad364e35

Adding a custom button to CRM 2011 Form

Adding a button to a CRM Form is quite challenging as we don’t have any IDE to design it. But still it’s possible using JavaScript.
Here’s the JavaScript code for that.
// Create the button, using the new_custombutton field as a container
        CreateButtonCRM5(‘swpmt_cancelddi’, ‘Cancel DDI’, ’75 px’, ’16_cancel.png’, CustomClickFunction);

// Custom Function
function CustomClickFunction() {
    var response = confirm(“DDI Status is to be changed to ‘Cancelling’. Do you want to continue?”);
    if (response) {

// Add a button to the CRM Form – Begin

// Create Dynamic Button for CRM 2011
function removeChildNodes(ctrl) {
    while (ctrl.childNodes[0]) {

function CreateButtonCRM5(fieldName, buttonText, buttonWidth, iconName, clickEvent) {
    functiontocall = clickEvent;
    crmForm.all.item(fieldName + “_c”).style.display = “none”;

    var li = document.createElement(“LI”);
    li.setAttribute(‘id’, fieldName + ‘LI’);
    li.setAttribute(‘className’, ‘ms-crm-Menu’);
    li.setAttribute(‘title’, buttonText);
    li.setAttribute(‘onclick’, functiontocall);
    li.setAttribute(‘onmousedown’, push_custom_button);
    li.setAttribute(‘onmouseup’, release_custom_button); = buttonWidth; = “hand”; = “center”; = “hidden”;

    var span = document.createElement(“span”);
    span.setAttribute(‘className’, ‘ms-crm-Menu-Label’);
    span.setAttribute(‘id’, fieldName + ‘Span’); = “hand”;
    li.onmouseover = function () { span.setAttribute(‘className’, ‘ms-crm-Menu-Label-Hovered’); }
    li.onmouseout = function () { span.setAttribute(‘className’, ‘ms-crm-Menu-Label’); }

    var a = document.createElement(“a”);
    a.setAttribute(‘id’, fieldName + ‘A’);
    a.setAttribute(‘className’, ‘ms-crm-Menu-Label’);
    a.onclick = function () { return false; }
    a.setAttribute(‘target’, ‘_self’);
    a.setAttribute(‘href’, ‘javascript:onclick();’); = “hand”;

    var img = document.createElement(“img”);
    img.setAttribute(‘id’, fieldName + ‘Img’);
    img.setAttribute(‘className’, ‘ms-crm-Menu-ButtonFirst’);
    img.setAttribute(‘src’, ‘/_imgs/ico/’ + iconName); = “hand”;

    var span2 = document.createElement(“span”);
    span2.setAttribute(‘id’, fieldName + ‘Span2’);
    span2.setAttribute(‘className’, ‘ms-crm-MenuItem-TextRTL’);
    span2.innerText = buttonText; = “hand”;

    removeChildNodes(crmForm.all.item(fieldName + “_d”));
    crmForm.all.item(fieldName + “_d”).appendChild(li);

function push_custom_button() { = “1px”; = “1px”;

function release_custom_button() { = “0px”; = “0px”;

// Add a button to the CRM Form – End

Windows PowerShell

PowerShell powers automating different tasks and Windows PowerShell is the Microsoft’s task automation framework, consisting of a command-line shell and associated scripting language built on top of, and integrated with the .NET Framework. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems.

Following links will be useful when dealing with PowerShell
PowerShell Tutorials – Variables
Invoking SQL and read files
Executing Sql Scripts
Execute all SQL files in a Directory with Powershell
Why This SQL Server DBA is Learning Powershell
Windows PowerShell -Replace (Search and Replace)

Create a Proxy in SQL Server Management Studio

Microsoft SQL Server Agent proxy accounts define a security context in which a job step can run.

To create a proxy account
1.In Object Explorer, expand a server.
2.Expand SQL Server Agent.
3.Right-click Proxies and select New Proxy.
4.On the General page of the New Proxy Account dialog, specify the proxy name, credential name, and description for the new proxy. Note that you must create a credential first before you create a proxy if one is not already available. For more information about creating a credential, see How to: Create a Credential (SQL Server Management Studio) or CREATE CREDENTIAL (Transact-SQL).
5.Check the appropriate subsystem for this proxy.
6.On the Principals page, add or remove logins or roles to grant or remove access to the proxy account.

Create a Credential in SQL Server Management Studio

A credential is required to connect from a outside resource to SQL Server. I needed to created a proxy to run an Integration Service and I wanted to create a credential for that.
MSDN says that a single credential can be mapped to multiple SQL Server logins and a SQL Server login can be mapped to only one credential. Only users with ALTER ANY CREDENTIAL permission can create or modify a credential.

1.In Object Explorer, expand Security, right-click Credentials, and then click New Credential.
2.In the New Credentials dialog box, in the Credential Name box, type a name for the credential.
3.In the Identity box, type the name of the account used for outgoing connections (when leaving the context of SQL Server). Typically, this will be a Windows user account. But the identity can be an account of another type.
4.In the Password and Confirm password boxes, type the password of the account specified in the Identity box. If Identity is a Windows user account, this is the Windows password. The Password can be blank, if no password is required.
5.Click OK.To create a credential