Wednesday, May 4, 2011

Generating EarlyBound CRM Entities using crmsvcutil.exe

To generate XRM.cs navigate to the sdk bin folder from the command prompt and use the below command
NOTE: This command works for crm 2011 online environment

CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration"   /url:https://crmtest.api.crm.dynamics.com/XRMServices/2011/Organization.svc   /out:Xrm.cs   /username:liveid   /password:password   /deviceid: deviceid /devicepassword: devicepassword   /namespace:Xrm   /servicecontextname:XrmServiceContext  /servicecontextprefix:Xrm


References:
http://msdn.microsoft.com/en-us/library/gg695782.aspx

Friday, April 29, 2011

Fetch XML 5000 Records Limitation


Have you ever tried to write a code which will get you all records from a specific entity? It's harder then you think it is! Everybody who is a bit aware of the CRM SDK thinks it should be a fetch statement like this:

<fetch mapping='logical'><entity name='account'><attribute name='accountid'/></entity>

WRONG!
This would only give you the first 5000 records in the database! It is written down in the SDK with small letters, but it could drive you crazy..

There are two solutions for this issue.
1) Add a registery setting to specify not to implement MaxRowsPerPage
2) Modify the fetch statement and merge several results

Here are the details for each solution
1st solution
Search in the SDK for the word "TurnOffFetchThrottling". You should add this as DWORD registery setting to HKLM\Software\Microsoft\MSCRM. Set the value to 1. You will now not have the 5000 records limit.

2nd solution
Modify your fetch statement to include paging and count numbers. Store all the data in an DataSet and perform that series of code over and over again as long as there is data coming.

Here's the script you should use to get all accountid's (for clarity and the ease of use I have added a function called "FetchDataSet").


private DataSet FetchAllAccountIds(){
int i=1;
bool bFinished = false;
DataSet dsAllData = new DataSet();
while (bFinished == false)
{
StringBuilder sbFetch = new StringBuilder();
sbFetch.AppendFormat("<fetch mapping='logical' page='{0}' count='5000'>", i);
sbFetch.Append("<entity name='account'>");
sbFetch.Append("<attribute name='accountid'/>");
sbFetch.Append("<attribute name='new_12_accountid'/>");
sbFetch.Append("</entity>");
sbFetch.Append("</fetch>");
DataSet dsTempResult = FetchDataSet(sbFetch.ToString());
dsAllData.Merge(dsTempResult);
if (dsTempResult.Tables[0].Rows[0]["morerecords"].ToString() == "0")
{
bFinished = true;
}
else
{
i++;
}
}
return dsAllData;
}

private DataSet FetchDataSet(string fetchXml)
{
string strResult = service.Fetch(fetchXml);
DataSet ds = new DataSet();
System.IO.StringReader reader = new System.IO.StringReader(strResult);
ds.ReadXml(reader);
return ds;
}


I hope this saves you some time!

Tuesday, April 26, 2011

Update Entity Record Using Rest EndPoint

Updating Complex Attribute types using rest end point in Jscript

          
            var lineitem = new Object();

             //Money Type Attribute
             var neu_amountchange_ref = new Object();
             neu_amountchange_ref.Value = neu_amountchange;
             lineitem.neu_AmountChange = neu_amountchange_ref;

             lineitem.neu_PercentChange = neu_percentchange;
             //updateRecord exists in JQueryRESTDataOperationFunctions.js
             updateRecord(id, lineitem, "neu_whatifmodellineitemSet", updateWhatifLineItmeCompleted, null);

Wednesday, April 20, 2011

Parse Json Date


 function getDateStringFromJson(jsondate) {

     var date = new Date(parseInt(jsondate.replace(/^\/Date\((\d+)\)\/$/gi, '$1'), 10));
     var curr_date = date.getDate();
     var curr_month = date.getMonth();
     curr_month = curr_month + 1;
     var curr_year = date.getFullYear();
     date= curr_month + '/'+ curr_date + '/'+ curr_year;
     return date;
 }

Friday, March 25, 2011

Get FetchXml From Advanced Find (CRM 4.0)

Open the advanced find and press CTRL+N , This will open the advanced find view in the new window.
Now design the query and click on the query button

In the address bar copy and paste the below script and press enter

javascript:void( new function() { var s=""; function f(p){ s+= p + "=" + eval("advFind." + p) + "\n\n"};f("FetchXml");prompt("my query:",s) } )


You will get the fetchxml in an alert



Thursday, March 17, 2011

Connecting to CRM 2011 Online


Connecting to CRM 2011 in the Cloud is trickier than connecting to CRM 2011 On Premise.

Check c:\Program Files to see if you have Windows Identity Foundation. If not you will need to install it.

You need to get some device credentials and this is done using a utility in the CRMSDK called DEVICEREGISTRATION. Go to \sdk\tools\deviceregistration directory and load deviceregistration.csproj. Compile the application and navigate to the \bin\debug folder. Open a command window and type

deviceregistration.exe /operation:Register