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 ( 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:
  2. BING Maps REST API :
  3. Unstructured URL: Get the latitude and longitude coordinates based on a set of address values for any country:
  4. CodePlex – Maps for CRM 2011 :

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. ( )

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. ( )

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 ( )

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”.