Where is my Layout XML?

I’m writing this mainly because it gets asked so much and in some cases the newbies are trying to figure out where on earth am I going to get the Layout XML to add a custom view or modify the lookup to use a different view.

Here is a quick way of accomplishing this.


Want to create a Layout XML string to be used in JavaScript on a form. Most of us know how to obtain the FetchXML using Advanced Find. that’s easy breezy.


  1. Create an empty solution and add the Entity in question which you are trying to change. If you are querying deep and want to display related records field values.
  2. Create a Personal View with the required layout. Save and Publish.
  3. Export this solution as an UNMANAGED Solution. Save the ZIP file.
  4. Unzip the solution file.
  5. Open customization.xml file using Notepad++ and under SavedQueries node for the entity in question, look for the Personal View you created using Name.
  6. Viola, you will see the LayoutXML and FetchXML.

Happy Customization.

CRM 2011: Increase export to excel limit (10000) – Different Approach

Installation Type: CRM Online an/or On-Premise.

Here is the solution if you have CRM Online. I know this works. Using Excel 2013(will not work on 2010).
1. Export a very small subset (say 100 records) of data using Web Client(Browser) using Export to Excel functionality.
2. In the Export dialog, choose “Dynamics Worksheet”. When finished, CRM will spit out an xxx.xml file.
3. Save to Desktop and open it within Excel 2013. Under the Data ribbon tab, select “Refresh from CRM”.
4. Once this is done and you see the exact same set as Export criteria, you can save this file as “.xlsx” file.
5. Create a oData query using open source tools to retrieve say contacts modified in last 30 days.
6. Under Data tab in Excel, “Choose a oData feed from ‘From Other Sources’ under ‘Get External Data’ group”.
7. Paste the oData query into the Browse text box and click NEXT, NEXT, OK.
8. Viola. It will be slow if you have lots of data and you might get kicked out during the import. Be careful with this approach since there is no way to cancel the download. If you have large sets of data, you might want to write oData query that will break it down into smaller pieces.

What I like with approach is it is not a change at Organization level. We can provide this as a feature for Power Users who is more interested in analytics using Power BI (PowerPivot/PowerView/PowerQuery). This approach will bypass the 10000 record limit with Export to Excel from CRM. Just now exported almost 33K contacts record with 19 columns of data. Not sure where the limit is for this approach.


Launch a Custom Activity form from Ribbon

Launch a Custom Activity form from Ribbon

Well, I had an interesting challenge at my current work and one of the problems that I have to solve is to prefill the Regarding field in an activity.


Not happy with the current operation of the Lead Qualify ribbon button. During Qualification, it allows users to create NEW records only. In some scenarios, it is necessary to select existing records, CONTACT, ACCOUNT and/or OPPORTUNITY. In addition to associating the Lead with existing records, I have to mark the Lead as qualified.

NOTE: I did not mess with the existing Qualify ribbon button.


At this point in time, there are only two ways to present custom UI to the end-user. a) HTML Web Resource (aka HTML + jQuery + AJAX),  b) Custom Activity Entity (minus left nav and ribbon cleaned out) and c) using Dialog(somewhat limiting). I choose to take path b) because I needed the flexibility to work with any entity. Dialog restricts the primary entity and hence all lookups and associations.


  1. Launch the Custom Activity default form from Ribbon button.
    1. If you have UR8 or later installed, you can make use of the handy function called Xrm.Utility.openEntityForm.
  2. Open new activity form with ‘Regarding’ field prefilled.
    1. This was a challenge since SDK still says that you cannot set regarding lookup. Below code is what I used to set a Regarding object. In my case it was Lead.
    2. function LaunchCustomActivityForm()
          var leadid = "698DAC01-B310-E311-8F98-B4B52F67D6E6";
          var leadname = "Debra Garcia (sample)";
          var acctid = "538CAC01-B310-E311-8F98-B4B52F67D6E6";
          var acctname = "A. Datum Corporation";
          var contactid = "2F8DAC01-B310-E311-8F98-B4B52F67D6E6";
          var contactname = "Maria Campbell";
          var params = {};
          params["pId"] = leadid ;
          params["pType"] =  4; //is the ObjectTypeCode
          params["pName"] = leadname ;
          //params["partyid"] = leadid ;
          //params["partytype"] =  4;
          //params["partyname"] = leadname ;
          // Open the window.
          Xrm.Utility.openEntityForm("new_customact1", null, params);
    3. Lauch the Custom Activity from Ribbon, you have to obtain the record Id and name to pass on to the above function. There is quite a bit of help around the web to figure this one out.
    4. Last step is to write a plugin that sets “Originating Lead” field to the Lead record. This can be post-op on “new_custact1” entity for either a create or update. Also set the Lead as Qualified during the Create
NOTE: Did not spend enough time to see why params with words “party…” is also needed. However just setting the pId, pName and pType are sufficient for the Regarding Lookup to identify the record and record type correctly.

Another bonus with this working this way is the regarding lookup correctly filters based on the record type. Also if you pass a ViewGuid, you can set the default view of this lookup. Oh well the options are endless. Even with the Polaris Flow UI, you can select an existing Contact or Account. You still cannot select an existing opportunity.

Hope this helps. Comments are always welcome.



GeoCode Workflow Activity for Dynamics CRM 2011


Finally, I got to complete two new custom workflow activities to GeoCode any CRM entity(OOB or Custom) using BING Maps or Google Maps. I started to look into Nokia Maps and kind of got lost in their HERE site. So lets dive into the details. This is the start of my passion for creating solutions that using mapping to present information to users. This passion started when working at Primedia (ApartmentGuide.com). My first exposure to Google Maps. Taking this to the next level by creating solutions that can be used within Dynamics CRM 2011, the ultimate extensible CRM platform.

This post will focus on a CRM power user creating a workflow incorporating these workflow activities. Don’t want to do injustice to the technology that went behind the workflow activities, which is REST service from map providers. Will discuss this aspect in more details in another post. Built this solution using a) Developers toolkit (SDK 5.0.13), Visual Studio 2012, and REST services provided BING Maps and Google Maps. Check Resources section at the bottom the blog, where I provide the links. Additionally, if you download the source from CodePlex, the workflow Activities themselves have the article and links in them.

NOTE: I’ve tested the workflow activities on an on-prem deployment only. Will test crm online and post any updates soon.

Update for CRM Online: Oct. 9th, 2013

I’ve tested the Google Maps custom workflow for CRM Online and workflows is working like a charm. When you register from source code, make sure to select Isolation Model = Sandbox. I’ve removed other errors about Partial Trust issues. Going to provide two solutions, one for Google Maps and one for BING Maps. Check CodePlex for individual solutions.

BING Maps Geocode Activity:

Using BING Maps REST Services Location API some more help from articles published on the MSDN sites, created this workflow activity. In order to get this going, follow instructions to obtain BING Maps Key from Account Center. We will walk through an example of Geocoding an account entity.

  1. Obtain BING Maps key from Bing Maps Account center. Create a new App to Specify the site as http://localhost .

    1. BingMapsKey

  2. Create a workflows that can run as an “On-Demand Process”. You can definitely make this process to run when a) Record is created and b) Record is updated and track the Address1, Address 2. You can Geocode more than one Address, by using the activity in multiple steps.
    2. Activities
  3. Set the Properties that are the input for the Bing Maps activity. a) Bing Maps Key b) Street c) City d) State e) Zip f) Country (ISO Code) . In this I did not spend too much effort in figuring out what makes good address, such as we need at least a ZIP to GeoCode. I will leave this as an exercise you can customize for your needs.
    3. BingMapsProperties
  4. GeoCode activity provides 3 output params a)Lat b) Long and c) GeoCodeResult. One more upgrade that I can do is to provide the quality of the result as an output params that can incorporated into the workflow.
    4. BingMapsOutput_LatLong
  5. Output param GeoCodeResult provided two pieces of info, a)BING Maps Geocode URL and b) first 1750 chars of the XML returned by executing the URL. Little bit about the URL. I use an Unstructured URL, which allows each part of the address to used based on what values are available as part of input params. You can take this URL and navigate in IE, since the output type that I ended up using is XML and view results. Helps with debugging results.
    5. BingMapsOutput_Result
  6. In the example solution provided on CodePlex, you take outputs Lat and Long and update the Account entity and output params Result is used to create a Note.

Next posts will delve into the details of what is happening within the activity when you Geocode an address. Additionally will be updating the CodePlex project with Geocode plugins for Account, Contact and Site. Well if you figure out for one, rest is the same. Will take baby steps. Want to build a SilverLight app that use make use of Bing Maps SilverLight control, make use of SQL 2008 Spatial querying.

Please provide any and all feedback to incorporate into these map utilities. Thanks for your time.

– P


  1. BING Maps account Center: https://www.bingmapsportal.com
  2. BING Maps REST API : http://msdn.microsoft.com/en-us/library/ff701713.aspx
  3. Unstructured URL: Get the latitude and longitude coordinates based on a set of address values for any country: http://msdn.microsoft.com/en-us/library/ff701714.aspx
  4. CodePlex – Maps for CRM 2011 : http://crmmaps.codeplex.com/

Javascript Date Library for CRM Page scripting

This is a quick help for all those Dynamics CRM 2011 souls out there dealing with page validation routines that invlove Dates. Javascript date manipulation is not for the faint of heart. This article does deal with date validation as in checking with date diffs, comparing dates and formating dates to be displayed as messages and also for setting dates in the correct formats whehn dealing with language and culture information other than english.

Date Comparision:

I started with a simple requirements. Check to see if one date is earlier than another date. First of allI cannot do this in Javascript.

var date1 = new Date(Xrm.Page.getAttribute(“firstDate”).getValue();

var date2 = new Date(Xrm.Page.getAttribute(“secondDate”).getValue();

In cannot do this in CRM event script

if (date < date2)   // this script will not run and will exit executinn of the function.

you have to take the diff and see if it is less than zero(0)

if ( (date – date2) < 0)  // this will actually fetch the difference in millisenconds and will be accurate.

Javascript Date Libraries:

First choice was to use Google DateJS library. As usual very drveloper friendly. I used Date JS, EN culture for formating date for error messages. One big issue I ran into with the library was that getAttribute would not fetch the date entered value on the form, would only fetch the date when form loaded. This was very annoying and had to dump DateJS. (http://code.google.com/p/datejs/ )

Second Choice, looked up Jacob Wright’s implementation of formating javascript dates and this would not work in the correct way either. Did not display the month correctly when using “m” as defined in the blog. This library did not interfere with Xrm.Page Data Entity methods. (http://jacwright.com/projects/javascript/date_format/ )

Third Choice was “F Is For Format” javascript library. Finally I got the javascript date formating to work correctly. Please check out this library at (http://fisforformat.sourceforge.net/ )

Enjoy and let me know if you see the behaviors of these libraries within CRM event model work any better or worse.

NOTE: I did not check out JQuery or JQuery UI to find a solution for date formatting, since I got my solution from “F is for Format”.


New to CRM 2011!

Welcome to Microsoft Dynamics CRM 2011. I’m dedicating this blog to developers who have this utopina dream of developing a solution that is easy for Operations to manage, User to be able to update the system on their own to support their business process and Executive teams seeing what they want. I’m new to CRM starting with CRM 2011. I beleive that Microsoft has come close to supporting this dream for developers by providing the XRM platform in CRM 2011. So far I have done the learning on my own, which I beleive is the best, however not the fastest way. I’m leaning on the shoulders of some who have gone through the pain and will post my experiences working with CRM 2011.

Below is list of resources that I ended up using to start with Dynamics CRM 2011. I’m assuming that you are already familiar with the following technologies that will make the ramp up process easier.

PreRequisites : (Don’t get overwhelmed by this list. On a day to day list of activities, you will get by with two or three technologies listed here. )

  • .Net 3.5/4; C#/VB/JScript
  • Data Related: T-SQL; ADO.NET; Entity Framework, LINQ, XML
  • Integration Platform: Windows Workflow, Web Services/SOAP, WCF, oData (CRM Rest Endpoints)
  • UI Platform: ASP.NET, SilverLight, JQuery/AJAX/JSON.
  • Security: AD and Claim-based Authentication

CRM 2011 Developer Training resources:

More to come. Enjoy CRM 2011!