POWEROBJECTS

718 Washington Ave. N. Suite #101
Minneapolis, MN 55401
View map and all Locations

Send us a message

This post is a sequel to a blog entry written late last year by my colleague Aki Rova. Click here to read more about it. 

crm2011

As pointed out by my friend Aki on his post, there’s quite of an interest out there from our group of users asking about the workflows ability (or its inability thereof) to send emails with an embedded hyperlink or URLs. This is most especially helpful if the user is making available certain resources from their company’s website or a hyperlink to the company’s web portal and most importantly a link to a record in a CRM entity as described in detail in the previous post.

What I worked on involved just a little bit more; the requirement was to make available a URL to an SQL report. The challenge is that we will need to pass a few parameters into that report. In short we needed to embed a dynamic URL to our little workflow generated email. And so off I went.

I really didn’t have an issue at all with building the dynamic URL; my approach was to do it at the record level. As a record gets created, a specific dynamic URL is also built and is persisted into a custom attribute in the record the next time it is loaded or after it is first saved.   The script that accomplishes this is really very simple.

OnLoad Event

//I wanna make sure that this small code will still work after org import/re-import

if (crmForm.ObjectId!=null &&

   crmForm.all.po_guid.DataValue!=crmForm.ObjectId)

{

  //the report guid is given here as a static parameter    

  reporturl1= “https://org.crm.com/crmreports/viewer/viewer.aspx?action=run&id={GUID}&context=records&recordstype=10005”;

  reporturl2 = “&helpID=report1.rdl”;

  //build the dynamic parameters

  param1 = “&records=” + crmForm.ObjectId;

  param2 = “&recordType=” + crmForm.all.po_reportParam.DataValue;

  crmForm.all.po_guid.DataValue = objectGuid;

  //build the complete URL with parameters

  crmForm.all.po_reporturl.DataValue = reportUrl1 + param1 + param2 + reportUrl2;

}

The next step is to build the workflow.   My next challenge is to be able to pass this report URL string into a workflow generated email and make it a hyperlink so users will just have to click on it. Now the out of the box feature doesn’t quite support this just yet. What it does is embed my report URL into the workflow generated email as a string. But I want to accomplish more than this.

Many CRM developers may already have had this challenge overcome before, and there could be many solutions out there, but the best solution we have found so far is through a workflow set of utilities that was made available from another Microsoft partner. Here is the link to the post by Jim Steger.

This URL Builder accepts a string parameter and embeds this URL into the workflow generated email.

All I need to do then is to pass my report URL from a custom attribute in my entity and into the URL field as illustrated above. What the URL Builder does is it adds a ‘href’ tag to the passed string to make it be a hyperlink when rendered in an email.

My initial tests proved that the solution was that simple, and so my next logical step was to have the solution deployed in production.

As I was monitoring how it was working in production, I had encountered an issue which didn’t make sense at first. The workflow was crashing that it had completely failed to work in production. No email ever came out from my workflow. I know that the URL that I was passing was correct because I can copy and paste it in a browser and it would always give me the resource that I wanted to access.

Took me several hours to figure out what ended up was a very simple mistake.   The URL Builder was assuming that all passed parameters are UTF-8 encoded. I was assuming that it would encode it for me, but then I fully understand now looking back that it wouldn’t be able to, otherwise encoding the whole URL string would give me an invalid URL.

The fix was simple, when I was building the URL – I individually encoded each parameter using the encodeURIComponent function in javascript. I could also do a complete encoding of all parameters by using the encodeURI function, but I chose the former because I wanted to singly work on each parameter for simplicity.

  //build the dynamic parameters

  param1 = “&records=” + encodeURIComponent(crmForm.ObjectId);

  param2 = “&recordType=” +

             encodeURIComponent(crmForm.all.po_reportParam.DataValue);

This issue here is simple, yet it could cost you a few hours, or even a day. Hopefully this post will save you from being in the same pit I was.

Avatar for JoeCRM

JoeCRM

Joe CRM is a CRM superhero who runs on pure Microsoft Dynamics CRM adrenaline. As the face of PowerObjects, Joe CRM’s mission is to reveal innovative ways to use Dynamics CRM and bring the application to more businesses and organizations around the world.