A macros system for Dynamics CRM - part two

In part one of this series, I explained the basic idea of what a macros system for Dynamics CRM is and a situation in which you'd want to use it instead of a workflow for process automation. In this post I'll explain the structure of the macros system and show the CRM entity form customizations that will be required to implement it. As I mentioned in part one, the idea underlying the macros system is that a user can trigger several distinct steps by clicking a single hyperlink. We achieve this by showing the user, via an iframe on the entity form, a page of hyperlinks specific to a given entity type. The macros page will also need to know the specific entity its actions will target. This requires the following:

In part one of this series, I explained the basic idea of what a macros system for Dynamics CRM is and a situation in which you'd want to use it instead of a workflow for process automation. In this post I'll explain the structure of the macros system and show the CRM entity form customizations that will be required to implement it.As I mentioned in part one, the idea underlying the macros system is that a user can trigger several distinct steps by clicking a single hyperlink. We achieve this by showing the user, via an iframe on the entity form, a page of hyperlinks specific to a given entity type. The macros page will also need to know the specific entity its actions will target. This requires the following:

  1. An iframe on the entity form in CRM.
  2. JavaScript code to load the macros page in CRM. (This isn't strictly required, but you'll get ugly errors in the create entity form if you specify the iframe URL directly.)
  3. A separate Web page per entity that will offer macros to do the work.

In this post I'll outline the first two steps, and I'll show sample code for the macros page in part three.

Creating the iframe

You'll need to add an iframe to your entity form in CRM. In our case we have a separate macros tab, but that's not required. If you have a long list of macros, I suggest putting them in a separate tab to keep things better organized.

Here are screenshots of the iframe properties window.


The iframe properties general tab

Note that we don't specify a URL for the iframe here. Also note that we have to allow cross-frame scripting.


The iframe properties formatting tab

Formatting has nothing to do with the functionality of the macros, but the formatting options shown here help maintain the illusion that the macros are part of the CRM application as opposed to something separate. Note that if you have a lot of macros, the no-scroll option will be a problem.

Loading the iframe

Once the iframe has been added to the entity form, you'll need to tell CRM how to load it. As I mentioned earlier, you could have specified the macros page URL in the iframe properties window, but if your macros page expects the entity Id to be sent via a querystring, it'll display an ugly error on a create form unless you build in error handling for missing values. That's not necessarily better or worse than dynamically loading the page via JavaScript, but the JavaScript load opens up a bunch of additional possibilities. For example, you might have customized macros pages based on the value of certain entity attributes that are can only be accessed via JavaScript.Open the entity form's OnLoad event properties and type in the following code:

    if ((crmForm.ObjectId != null)&&(crmForm.ObjectId))
    {
    var policyId = crmForm.ObjectId.replace("{","").replace("}","");
    var macrosite = "http://PATH_TO_MACROS_PAGES/policy_macros.aspx?guid=" + policyId;

    crmForm.all.IFRAME_macros.src = macrosite;
    }

Make sure the event is enabled, and you're ready to run the code that I'll show in the final part of this series.

comments powered by Disqus