GeoCode Plugin using Google Maps or BING Maps

Overview:

In my previous post, I talked about building a Custom Workflow Activity that works for CRM 2011 Online and CRM 2011 On-Premise. Now decided to build a geocoding plugin which will do the same, except it is like Turbo the snail. Designed it in such a way, you can make this to work for any Entity, OOB or Custom and for any number. Any secrets, naaaahhhhh. Just plain old CRM. That’s what I like about CRM. It is LEGO blocks. No end to creativity. Created a config entity to hold all config data, be it Google Maps or Bing Maps. Ok, enough of the blah, blah, blah. Just get to the meat will ya. I felt there might be a need to goecoding to be synchronous, rather than a workflow. Well with 2013, that will change with Realtime Workflows.

Solution:

In this post I will deal with deploying, customizing and seeing the results of the plugin executing. Will post the source code online at Codeplex(https://crmmaps.codeplex.com/) when I make myself a bit free. Will provide a managed solution with just the plugin and config entity.

Step 1: Import Maps Solution.

Once you import the solution, you should see a new Group on sitemap under settings called E31 Maps. This will give you access to Geocode Config entity.

Step 2: Geocode Config Entity entries

In this step, I’m assuming you are adding a record to geocode an address in Account entity.

Entity Name = account(this is the logical name, not schema name of the entity).

Keeping with the above guideline, please fill in the names of the fields that are the key players in the geocoding process.

Inputs:

  • Entity Name
  • Bing Maps Key ( can be empty when using google maps url)
  • Bing Maps Url, or Google Maps Url
  • Street Field(name of the field in contact entity which hold the Street Address value)
  • City Field (name of the field in contact entity which hold the City value )
  • State Field (name of the field in contact entity that holds the State or Province value)
  • Postal Code Field (name of the field in the contact entity that holds ZIP code value)
  • Country Field

Outputs:

  • Latitude Field (name of the field that will hold geocoded Latitude value in contact entity)
  • Longitude Field (name of the field that will hold the geocoded Longitude value in contact entity).

Example of screenshot for Account entity:

GeocodeConfig_Account_Bing

Geocode Config record values for geocoding Account entity using BING Maps

Step 3a: Plugin Registration – New Step for CREATE

Once the Plugin is registered as part of the installation of the managed solution, fire up the Plugin registration tool supplied with 2011 SDK. Create a new STEP for this assembly as shown below.

Bing_Create_Account

STEP Configuration settings for Account CREATE Message

Step 3b: Plugin Registration – New Step for UPDATE

Want to finish the configuration for the UPDATE message so that you can go ahead and fire up the plugins by creating accounts or updating accounts.

  1. Create a new STEP for the assembly for the UPDATE message,
  2. In the Step Configuration section, please select the Filtering attributes to be Input attributes as mentioned in the previous section. The 5 attributes are a) Street, b) City, c) State, d) Zip and e) Country.
  3. Fill in other parts of the Step configuration screen as shown below.

    Bing_Update_Account

    STEP Configuration settings for Account UPDATE Message

  4. Create a PreImage for the UPDATE message step. It is important that I know the records previous address information before the change occurred. Set up the PreImage for these 5 fields. Mainly the ones that you need to compare with the changed values. These fields are picked from the entity for which you registered UPDATE step for. In our case we are dealing with Account. Select these 5 fields only for the PreImage address1_city, address1_country, address1_stateorprovince, address1_line1, address1_postalcode
    Bing_Update_Account_PreImage

    PreImage Setting for Account UPDATE step.

    There you go. You are done. Way the geocoding works is pretty simple. For a Create message, no need for any explanation. I pass in values that are available to the BING Maps geocode api. Bing maps returns a result and result quality(next release). For the Update operation, it is little bit tricky. CRM will send only the fields that changes to the event. In the case for fields that have not changed I get the value from PreImage. then I do the usual processing in passing all values that are parts of the address to the geocode API. Viola. I tested with CRM Online and works. Now you need to tell me if there are other features that must be added to this and if it is performing well.

NOTE: It is up to you as a developer to register the appropriate STEPS for the respective Geocode API, if it is BING or GOOGLE. This article is primarily is focused on BING Maps API. I’m working on a release of the plugin that uses Google Maps API. Both plugins will make use of Geocode Config entity to decide where the address fields are in the entity record in question.

As always comments are welcome. enjoy!

Download Solution : https://crmmaps.codeplex.com/

Prabhakar

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.

Problem:

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.

Solution1:

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.

Challenges:

  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()
      {
      
          debugger;
      
          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.

Thanks,

Prabhakar