Friday, 18 November 2011

Open the url in a new window

In order to open the window in new browser, rather then in a tab of already opened browser, use nomerge argument


Process objProcess = Process.Start("IEXPLORE.EXE", "-nomerge http://google.com/");

Thursday, 10 November 2011

Url Encode/Decode

System.Web.HtmlUtility.Encode("http:\\www.yahoo.com\main.aspx?audit%20history")

output

http:\\www.yahoo.com\main.asp?audit history

Wednesday, 9 November 2011

Step by Step for CRM 2011 plugin

1. Create a class library project,
     Make sure the Target framework is set to ".Net Framework 4"

 2. Sign the assembly by going to project properties and selecting Signing tab, and selecting check box "Sign the assembly", select new and enter name.

 3. Add following references
        microsoft.crm.sdk.proxy
        microsoft.xrm.sdk

4. Add the following namespace to plugin class
using Microsoft.Xrm.Sdk

5. Implement IPlugin interface so it look like e.g

   public class MyPlugin :IPlugin
   {
      public void Execute(IServiceProvider serviceProvider)
     {

      }
    }

6. Build the project and copy and paste the plugin dll and pdb file to

C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly

7. Open Plugin registration tool, Click on register assembly and select the assembly from the above mentioned location
   Select location as Disk

8.Register new step by selecting the assembly in the plugin registration
  Message: Update
  Primary Entity:contact
Secondary Entity:none
Eventing Pipeline Stage of Execution: Pre-operation (CRM 2011 Only)
Execution Mode: Synchronous
Deployment: Server

9.   In the visual studion, go to process and select attach to process, and select the w3wp process, and add the break point with in execute method.

10. update a contact record. The code break point will hit to debug.

Registering PreImage in plugin

Select Organisation in Plugin registeration tool, and select step and then select register Image,

Entity ent= (Entity)context.PreEntityImages["incident"];
                if (ent.Attributes.Contains("attributename"))
                {
                    string attrValue = (string)ent.Attributes["attributename"];                 
                }



http://crmconsultancy.wordpress.com/2010/10/25/plugins-in-crm-2011/
    

Tuesday, 8 November 2011

OData


1. include jquery, and jso library

/////////////////
To hide a field use

Xrm.Page.getControl("attributename").setVisible(true);

if it doesn't work then use

document.getElementById("attributename_c").style.display = "inline/none";
document.getElementById("attributename_d").style.display= "inline/none";

use inline to show, and none to hide the field
////////////////

To change the required field level use

 Xrm.Page.getAttribute("to").setRequiredLevel("required");

valid values are none, required and recommended

///////


function UpdateActivity()
{

    var CRMObject = new Object();
          CRMObject.proprtyname = value;
          updateRecord(guid, CRMObject, "EntityNameSet", null, null)
}

Friday, 4 November 2011

Custom ribbon button is disabled after importing solution of customisation

Custom ribbon button is disabled, when imported solution.zip file of solution, everything is fine but buttons shown are disabled,

Resolution: reset iis and re-import customizations

Show dialog on custom ribbon button


Created a custom ribbon button on case entity and on click of button show a dialog. on completion of dialog refresh entity form.
....
<CustomAction Id="NewCancel" Location="Mscrm.Form.incident.MainTab.Actions.Controls._children">
            <CommandUIDefinition>
              <Button Id="NewCancelButton" ToolTipTitle="$Resources:Ribbon.Form.incident.MainTab.Actions.Cancel" ToolTipDescription="$Resources:Ribbon.Tooltip.CancelCase" Command=AbandonCase" Sequence="6" Alt="$Resources:Ribbon.Form.incident.MainTab.Actions.Cancel" LabelText="Abandon Case" Image16by16="/_imgs/ribbon/CaseCancel_16.png" Image32by32="/_imgs/ribbon/CancelIncident32.png" TemplateAlias="o1" />
            </CommandUIDefinition>
          </CustomAction>

....

<CommandDefinition Id="AbandonCase">
            <EnableRules>
              <EnableRule Id="IsExisting" />
            </EnableRules>
            <DisplayRules />
            <Actions>
              <JavaScriptFunction FunctionName="AbandonCase" Library="$webresource:new_incident.js" />
            </Actions>
          </CommandDefinition>

then created a javascript function to show dialog when user click on the custom button


AbandonCase = function () {
    window.showModalDialog(OrganisationPath + "/cs/dialog/rundialog.aspx?DialogId=" + AbandonCaseDialog + "&EntityName=incident&ObjectId=" + Xrm.Page.data.entity.getId());
    refreshEntityForm();
}



refreshEntityForm = function()
{
  //used mainly from ribbon buttons

  if (Xrm.Page.data.entity.getIsDirty())
  {
      // Save form - causes reload
      Xrm.Page.data.entity.save();
  }
  else
  {
     // Reload form.
      window.location.reload(true);
  }
}





Disable all the fields on a form,