Wednesday, April 24, 2013

How to access Parent Form Attribute in CRM form.


you can access the property using window.top.opener

Lets i have to access the property of parent lookup form and set into it.then you can use the following code

var previous = window.top.opener.Xrm.Page.getAttribute("customerid").getValue();
previous[0].name = Xrm.Page.getAttribute("firstname").getValue() + " " +  Xrm.Page.getAttribute("lastname").getValue();
window.top.opener.Xrm.Page.getAttribute("customerid").setValue(previous);


same way if i want to get the value from parent form then

var previous = window.top.opener.Xrm.Page.getAttribute("firstname").getValue();

This is unsupportive way.


Execute workflow using javascript in CRM 2011




function RunWorkflow() {
    var _return = window.confirm('Are you want to execute workflow.');
    if (_return) {
        var url = Xrm.Page.context.getServerUrl();
        var entityId = Xrm.Page.data.entity.getId();
        var workflowId = '437DDF9B-EE32-4E88-91CF-544B49179F58';
        var OrgServicePath = "/XRMServices/2011/Organization.svc/";
        url = url + OrgServicePath;
  var xml = "" +
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
    Xrm.Page.context.getAuthenticationHeader() +
    "<soap:Body>" +
    "<Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
    "<Request xsi:type=\"ExecuteWorkflowRequest\">" +
    "<EntityId>" + entityId + "</EntityId>" +
    "<WorkflowId>" + workflowId+ "</WorkflowId>" +
    "</Request>" +
    "</Execute>" +
    "</soap:Body>" +
    "</soap:Envelope>";

  var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
  xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
  xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
  xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
  xmlHttpRequest.send(xml);
 }
}

Tuesday, April 23, 2013

Create Early-Bound Entity Classes with the Code Generation Tool (CrmSvcUtil.exe) in CRM 2011


You can find the utility in the SDK download package in the SDK\Bin folder.The classes created by the code generation tool are designed to be built into a class library that can be referenced by projects that use Microsoft Dynamics CRM. After you have generated the classes using the tool, you should add the file that contains the classes to your Visual Studio project or solution

Assemblies Need to Include
Microsoft.Crm.Sdk.Proxy.dll
Microsoft.Xrm.Sdk.dll

Run the Code Generation Utility
Run this utility from the SDK\Bin folder. If you run the utility from another location, the Microsoft.Xrm.Sdk.dll assembly, located in the SDK\Bin folder, must be located in the same folder

Format for running the utility from the command line
CrmSvcUtil.exe /url:http://<servername>/<organizationname>
/XRMServices/2011/Organization.svc /out:<outputfilename>.cs /username:<username> /password:<password> /domain:<domainname> /namespace:<outputnamespace> /serviceContextName:<service context name>


Open Visual command Prompt and then Go to the path sdk/bin in CRM sdk and then write below commnad if you are using the
CRM online

CrmSvcUtil.exe /url:https://org.api.crm5.dynamics.com/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /username:"myname@mubnam.onmicrosoft.com" /password:"password" /deviceid:"23pq434ldg5nqps9h4ivlngbfv" /devicepassword:"J-n60IPL7h;Ga`b5##SsIHJM"


Examples to use the code generation utility from the command line for each deployment type
Claims Authentication Active Directory
CrmSvcUtil.exe /url:http://CRM2011:5555/Org/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /username:administrator /password:password"


Claims Authentication - IFD
CrmSvcUtil.exe /url:https://org.crm.com:5555/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /username:administrator /password:p@ssword!

Monday, April 15, 2013

Write a common plugin for Create/Update/Delete events in Dynamics CRM 2011

If you want to write a common plugin for Create/Update/Delete events in Dynamics CRM 2011 then only you need to take care of “context.InputParameters["Target"]“. In case of Create/Update event “context.InputParameters["Target"] is Entity” and in case of Delete event “context.InputParameters["Target"] is EntityReference”. Below is the sample code for the same:


public void Execute(IServiceProvider serviceProvider)
{
     // Obtain the execution context from the service provider.
     IPluginExecutionContext context = (IPluginExecutionContext)
     serviceProvider.GetService(typeof(IPluginExecutionContext));
     // Obtain the organization service reference.
     IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
     IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
     // The InputParameters collection contains all the data passed in the message request.
     if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
     {
          if (context.MessageName == "Create")
          {
               //Code to be executed during Create event of an entity
          }
          else if (context.MessageName == "Update")
          {
               //Code to be executed during Update event of an entity
          }
      }
      else if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
      {
          if (context.MessageName == "Delete")
          {
              //Code to be executed during Delete event of an entity
          }
      }
}