Advertisements

Archive

Posts Tagged ‘XrmServiceToolkit’

Retrieve records with Fetchxml using Jscript – CRM 2011

June 20, 2013 1 comment

Retrieve the records using FetchXML is a convenient way as we can form the FetchXML easily using the ‘Advanced Find’ .

Download Fetch XML

Download Fetch XML

Once you have the FetchXML ready, below is the JScript to execute and read the result set.

  • In this sample, I am fetching records from custom entity “Bikes” which has relationship with ‘Contact’ entity. (i.e., Fetch all the bikes of a Contact whose full name contains ‘Raj’)
  • Note – I am using “xrmservicetoolkit” helper Jscript which is available in CodePlex. You just need to download the Jscript and refer to your CRM form.

function getBikesByContactName() {

var fetchXml =

“<fetch mapping=’logical’>” +

“<entity name=’raj_bike’>” +

“<attribute name=’raj_name’ />” +

“<attribute name=’createdon’ />” +

“<link-entity name=’contact’ from=’contactid’ to=’raj_customerid’ alias=’ad‘>” +

“<attribute name=’fullname’ />” +

“<filter type=’and’>” +

“<condition attribute=’fullname’ operator=’like’ value=’%raj%’ />” +

“</filter>” +

“</link-entity>” +

“</entity>” +

“</fetch>”;

// Execute the fetch

var bikes = XrmServiceToolkit.Soap.Fetch(fetchXml);

// Get the results by loop through ‘bikes’

for (var indxBikes = 0; indxBikes < bikes.length; indxBikes++) {

alert(“Bike Name – “+bikes[indxBikes].attributes.raj_name.value);

alert(“Created On – “+bikes[indxBikes].attributes.createdon.value);

// Get the related entity (i.e., Contact) attributes using LinkEntity alias)

alert(“Related entity attribute (Contact Name) – ” + bikes[indxBikes].attributes.ad.fullname.value);

}

}

🙂

Advertisements

XrmServiceToolkit for CRM 2011

XrmServiceToolkit is a JavaScript library which can be used for JavaScript Development under the platform for CRM 2011 environments.

Download from Codeplex link http://xrmservicetoolkit.codeplex.com/

It contains single jscirpt file “XrmServiceToolkit.js

The library contains three major parts regarding functions.

  • Common: General Methods used for various purpose.
  • Rest: Organization Data Service functions including CRUD, Associate, Disassociate, etc
  • Soap: Organization Service functions including CRUD, Fetch, Associate, Disassociate, etc

🙂