Wednesday, September 12, 2012

Data Access using O-Data Service in CRM 2011.

Introduction

Here I am going to show you how to access the Data using O-Data service.
Here the Scenario..Lets see In Contact Form when I Select the Parent Customer the Main Phone of the Parent Customer value will be stored in Home Phone of the Contact.For that we have ro create a Function and call the Function in Onchange Event of that ParentCustomer in Contact Form.

function checkParentAccountPhone()
{
       //alert("hello");
if(Xrm.Page.data.entity.attributes.get("parentcustomerid").getValue() != null)
{
                   // if  CRM has multiple organization.                    
                   var serverUrl = location.protocol + '//' + location.host+ '/' +  Xrm.Page.context.getOrgUniqueName();;
                  //else
                   var serverUrl = location.protocol + '//' + location.host;
                   var parentid=Xrm.Page.data.entity.attributes.get("parentcustomerid").getValue()[0].id;
   alert(parentid);
   var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";

  oDataEndpointUrl += "AccountSet?$select=Telephone1&$filter=AccountId eq guid'" +  parentid + "'"
  var service = GetRequestObject();
                  Xrm.Page.getAttribute("address1_line1").setValue(oDataEndpointUrl );
  if (service != null)
 {
service.open("GET", oDataEndpointUrl, false);
       service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");
service.setRequestHeader("Accept", "application/json, text/javascript, */*");
service.send(null);
var requestResults = eval('(' + service.responseText + ')').d;

if (requestResults != null && requestResults.results.length > 0)
{
                                 Xrm.Page.getAttribute("telephone2").setValue(requestResults.results[0].Telephone1);

}
}
    }
    return false;
}
function GetRequestObject()
{
    if (window.XMLHttpRequest)
        return new window.XMLHttpRequest;
    else
    {
        try
        {
            return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch (ex)
        {
            return null;
        }
    }
}

function errorDisplay(XmlHttpRequest, textStatus, errorThrown)
{
     alert(errorThrown);
}

Save above in .js File.and Call the Function checkParentAccountPhone from OnChange Event of Parent Customer.
For How to call Javascript use my below link

http://microsoftcrmkartik.blogspot.in/2012/06/javascript-in-crm-2011.html

Tuesday, September 11, 2012

Qualified Lead in CRM 2011.


SetStateRequest request = new SetStateRequest
{
               EntityMoniker = new EntityReference("lead", new Guid(leadduns["leadid"].ToString())),
               State = new OptionSetValue(1),
               Status = new OptionSetValue(3)
};
 _service.Execute(request);

Friday, September 7, 2012

How to Debug Plugins using Profiler.


One can debug CRM plug ins without connecting to CRM server or without remote debugging.

Here are the steps as in how you can use Profiler for debugging plug ins:
   1>     Connect to CRM using plugin registration tool of March SDK 2012.

   2>      Click on Install Profiler
         

   3>     You will find a new node attached to registered plugins “Plugin Profiler”.






   4>     Select a plug-in step and click Profile to enable profiling.



5>     Then start your plugin from MSCRM i.e if your plugin is on update perform  update operation and download the error file.
6>     Then in Visual Studio attach to process “plugin registeration.exe”. Add the breakpoint  from where you would like to debug.



7>     Then click on Debug in plugin registration tool.


8>     In Profile location provide the path of the error log of the plugin.

9>     In Assembly location provide the dll of the plugin from which you got error.

10>     Then select the Plugin class from Plug-in. This drop down will contains all classes present in the dll.

11>     To start debugging just click on Start Plug-in Execution.