In this webinar, our experts showcase a variety of demo use cases of how different components of the...
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.
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.
Hi
If I were to use this for a workflow that would send a link to a report that displayed all neglected cases where would I put the JavaScript?
Would I need to put it on the Case main form onload event?
Would it allow me to send a link for a report than runs for all neglected cases or would it only show me one individual neglected case?
Another question is when to trigger this workflow... Have you got any suggestions?
Thanks
Sander
As with my example above, I had put my js script in the onload event of my form. I believe you have a pretty similar requirement as the example above - so yes you can write your js unto the onload event.
The main driver to the example script above is the report guid, this is what tells the ReportServer what report you want to access. Depending on your requirement you can either do the former or the latter. You can pass parameters into a report at runtime by building your own URL as my example above shows, and by so doing - you can zoom into the record specific report, or be able to retrieve a bigger subset.
I would suggest triggering the workflow after a specific event in a case occurs, say after a case has been assigned to a rep, that way you know who to send this email notification to.
Hope that helps
I have a similar, but slightly different issue that I am trying to solve:
I want to send an email to the primary contact of a support case, upon the resolution of that case, and I would like to send a url that has the case number (dynamic value)embedded into it so that I can capture the survey results for that particular case. I have not been able to do this. Any ideas would be appreciated
Hi Kathy,
Microsoft has released a set of workflow 'productivity tools'. THis includes the url builder mentioned in our blog above. It also includes a 'create generic hyperlink' option for workflows.
You can download it here:
http://crmaccelerators.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=26691
thx.
Alex
Hi
Please i have a question
po_guid, reporturl1 and reporturl2, they refer to what exactly ??
Thanks