Getting Related Record Lookup Fields with Retrieve Multiple Using The REST Endpoint With JavaScript in Dynamics CRM

There are multiple ways to get a data about related entity lookup in Dynamics CRM, like using SOAP or OData endpoint which are explained in SDK, but here I’m going to use a optimized JavaScript library called XrmServiceToolkit. You can get this library from CodePlex.

This library has built on JSON and JQuery and has multiple functionality that enable you to use SOAP or Rest or other functionality in one place.

In order to use this library download it from codeplex and add them to your Dynamics CRM form libraries.(json2, jquery, xrmservicetoolkit)


for instance I want to get some data about “Existing Product” lookup in “Opportunity Product”  entity, to do some calculation on the form.

In opportunity product form I add my library called “Opportunity_Product_JS” to use XRMServiceToolkit, RetriveMultiple method:

function calcQuantity() {
//getting id and name of the lookup record to use in our RetriveMultiple filter
var objProduct = Xrm.Page.getAttribute("productid");
if (objProduct != null) {

var objProductValue = objProduct.getValue();

if ((objProductValue != null)) {
//getting  name of the lookup
var lookuptextvalue = objProductValue[0].name;
//getting id of the lookup
var prodId = objProductValue[0].id;

if (prodId != null) {

var myResult = getLookup(prodId);
//do your calculation with myResult


//function will return the lookup data
function getLookup(prodId) {
 var res;

  //you can get this from your OData endpoint in setting/developer resources. 
  //search for your entity name in XML. it follows this rule: entityname+set

  "$filter=ProductId eq guid'"; + prodId + "'",
  // filter will search for a product that is defined inside the lookup and will put it in the result

 function (results) {
 //Important Note:If you expect more than one page (50) of records
 // this function should loop through the results and push the records into an array outside of the function.

   var res = results; 
  //if your filter returns more than 50 records this statement will return incorrect results.Follow the link at the end of this post!

  function (error) { alert(error.message);},
   function onComplete() {  },
return res;

Also check this blog post for more comprehensive overview of XrmServiceToolkit.Rest.RetrieveMultiple.

Override Created On field in Microsoft Dynamics CRM

If you are importing data manually , CRM will handle Createdon field and you can map it to your datetime field in your CSV file (could not be future date).

But if you are writing code, It’s impossible to change or update the created on field directly in Dynamics CRM while creating a new record pragmatically,

Instead of using Created on field you can use overriddencreatedon field and this field will update the created on field in the background.

overriddencreatedon is available in all entities and it’s display name is Record Created On.

for instance if you create a record with the actual creation date of 10/17/2010, and pass  it to overriddencreatedon, interestingly  CRM will store the 10/17/2010  in Created on field and will update the overriddencreatedon with the date that you performing that action in CRM.

Once you create the record you can’t modify creation date anymore and it’s only accessible while creating.

Using Informatica Cloud application to integrate propriety ERP system with Dynamics CRM

With release of office 365 cloud application and Dynamics CRM 2013 online, I’ve seen lots of SalesForce customers are switching to use Microsoft Dynamics CRM 2013.  it’s cheaper in the long run and will integrate better in enterprise environment with Microsoft back end and Microsoft office outlook.

One challenge of this transition would be transferring current integration from SalesForce to Dynamics CRM. Talking about integrating SalesForce and other systems, I find Informatica one of the best solution out there but when it comes to Microsoft Dynamics, it’s not as good as it should be, for instance it does not support CRM lookups inside the interface and you can’t do lookup directly inside the interface, and it also doesn’t give you much details while running integration, like number of rows before running integration.

There are two ways to do Dynamics CRM lookup in Informatica, using Visio informatica add-on or using easier way which is flat files.
in the next post I will talk about flat file Dynamics CRM lookup in Informatica.


If yo want to integrate Dynamics CRM and Dynamics GP sales information, which might be customers and invoices and orders, etc, you need to have salespersons defined and identical in each system. so once you run the integration, you can assign the records from GP to appropriate owner in CRM.

This is the query to get the salespersons from  GP database:

  select RM00301.SLPRSNID,RM00301.SLPRSNFN , RM00301.SPRSNSLN, RM00301.SALSTERR,   * from RM00301
  where RM00301.INACTIVE='0'

Hiding form components in Dynamics CRM 2013

With new release of CRM 2013 we can use Business Rules to do some simple actions based on conditions on the forms, but business rules are limited some how and most of the time i tend to use JavaScript to perform more specific actions on the form. one of these scenarios is explained below.

For hiding form components like buttons  in Dynamics CRM you can use IE developer (F12) or Firefox firebug  and javascript. here are the steps for hiding a grid + button on the form:

  • Open a sample record in CRM
  • If you are using IE, press F12 to fire up IE developer
  • In IE developer click on select arrow tool


  • with the arrow selected move to the area you want to hide, in this example a plus button  in grid (it will select the container that you want by hover over that area)selected
  • go the IE developer and look for the id=”xxxxxx” in the line selected id
  • Use this JavaScript code and update the code with Id that you’ve got from last step and run it onLoad event of form.
function hideButton()
var obj=document.getElementById("Your ID");"none";

note: it’s unsupported customization.