Embedding Direct Links To CRM In A Workflow Email

I can't think of a single CRM implementation that I've been involved in where workflow was not used to send any emails.  Every implementation has used the workflow engine to send emails when records are created, ownership changes, or when Opportunities are closed as a win/loss.  The workflow engine is robust enough where we can embed a lot of detail into the body of the email about the record itself, but what if the user wants to actually view that record in CRM?  Even in the Outlook client this can be a 3 step process:

  1. Open up the Email
  2. Click View In CRM, this opens up the actual email activity in CRM, not the record we want to view
  3. Click the Regarding Object Link

Now you are finally at the actual record you want to view.  If you have Office 2007 there is now a button on the ribbon called View Regarding which cut's out a few steps from above.  If you're not fortunate enough to be using Office 2007 yet, wouldn't it be nice if you could just embed a link in the body of the email message that provides a direct link to the record in CRM?  Fortunately, it's relatively easy to do with a custom attribute and a little bit of Javascript. 

Step 1 - Create A Custom Attribute To Hold The URL
For this example we'll just call our attribute:  new_urllink with datatype varchar

Step 2 - Add The Appropriate Javascript to the OnSave() Event
The Javascript required varies depending on whether the entity is a custom entity or a standard out of the box entity.  The Javascript is labeled appropriately below.  The Javascript checks to see if this is an update form and that the new_urllink attribute is empty.  If it is, then it will build the Url link.

Use the code below for a standard CRM entity (Example Below is for the Account Entity):
var objId;
var accountUrl;
if((crmForm.all.new_urllink.DataValue == null) || (crmForm.all.new_urllink.DataValue == ""))
{
   if(crmForm.FormType == 2)  //Checks to see if this is an update Form  (value of 2)
   {
        var embedUrl;
        accountUrl = "http://crmdemo/sfa/accts/edit.aspx";   //Default Path to the Edit.aspx page for an Account
        objId = crmForm.ObjectId;  //Retrieves the ID of the current object
        embedUrl = accountUrl + "?id=" + objId;  //pieces together the items required for a full Url
        crmForm.all.new_urllink.DataValue = embedUrl;  //Sets the value of the field
        crmForm.all.new_urllink.ForceSubmit = true;
        crmForm.Save();
    }
}

Use the code below for a custom CRM Entity:
var objId;
var objType;
var customUrl;
if((crmForm.all.new_urllink.DataValue == null) || (crmForm.all.new_urllink.DataValue == ""))
{
     if(crmForm.FormType == 2)
     {
          var embedUrl;
          customUrl = "http://crmdemo/userdefined/edit.aspx";
          objId = crmForm.ObjectId;    //Gets the ID of the current record
          objType = crmForm.ObjectTypeCode;  //Gets the type code of the custom entity
          embedUrl = customUrl + "?id=" + objId + "&etc=" + objType;  //pieces together the Url
          crmForm.all.new_urllink.DataValue = embedUrl;
     }
}

Step 3 - Create The Associated Workflow
Now you can create a notification workflow and all you need to do is add this new_urllink field to the body of the email. 

Step 4 - Your Done!

A List of Common Url's For CRM Entities:
You can find the paths for CRM Entities rather easily by browsing to the home directory of the CRM Website, if it's installed on the default website the path would be <drive>\inetpub\wwwroot.  Once you have access to the CRM Website files find the folders that contain the edit pages for the various entities:

  •  SFA - Sales Force Automation (accounts,contacts etc)
  •  CS - Customer Service (cases,contracts etc)
  •  MA - Marketing Automation (campaigns, marketing lists etc)


Sales Force Automation:
Accounts:  http://<crm-url>/sfa/accts/edit.aspx
Contacts:  http://<crm-url>/sfa/conts/edit.aspx
Leads:  http://<crm-url>/sfa/leads/edit.aspx
Opportunities:  http://<crm-url>/sfa/opps/edit.aspx

Marketing Automation
Campaigns:  http://<crm-url>/ma/camps/edit.aspx
Marketing Lists:  http://<crm-url>/ma/lists/edit.aspx
Campaign Response:  http://<crm-url>/ma/campaignresponse/edit.aspx

Case Management:
Cases:  http://<crm-url>/cs/cases/edit.aspx
Contracts:  http://<crm-url>/cs/contracts/edit.aspx
KB Articles:  http://<crm-url>cs/articles/edit.aspx

Custom Entities:
Custom:  http://<crm-url>/userdefined/edit.aspx

*Please substitute the actual url of the CRM Implementation you are working with where you see <crm-url> in the links above.


 


Posted Jun 27 2007, 09:48 PM by Jeremy Winchell

Comments

vbullinger wrote re: Embedding Direct Links To CRM In A Workflow Email
on 06-28-2007 12:40 PM

This is pretty big.  It really infuriates me that it you can get every single bit of information from an entity in a workflow email, but you can't get the ID of the item.  That's the most important one.  I've done some things to get this done, but none of them were this simple.  This is definitely how I'm going to do it from now on.  I'm kind of disappointed in myself for not thinking of it, to be honest :)

The only thing that any reader of this post needs to realize is that this will work for ALMOST every workflow rule set.  The one for which it won't?  On create.  As in, this code goes in the onload event handler.  So... the entity needs to have been created before.  If you hit "save and close," it will save all the fields and NOT fire off this code.  Then, if you have a workflow rule up that responds to an entity's creation, trying to link to the newly created entity, the new_urllink will NOT be populated yet.  If, on the other hand, you open up the entity after it's created to, say, reassign it to another person, then it will save the new_urllink and any workflow made in response to this will, indeed, work.  Good post.  When I have some free time (next week, hopefully), I'll look into how to (easily) get this to work upon creation.

Jeremy Winchell wrote re: Embedding Direct Links To CRM In A Workflow Email
on 07-09-2007 11:08 AM

The post was changed to trigger the code when the OnSave() event is triggered.

vbullinger wrote re: Embedding Direct Links To CRM In A Workflow Email
on 07-31-2007 11:32 AM

Though it's a better place (the OnSave() event), it does not solve the problem posed by OnCreate().  OnSave() actually happens BEFORE OnCreate().  Therefore, we still don't know the ID.

Ray wrote re: Embedding Direct Links To CRM In A Workflow Email
on 08-21-2007 10:05 PM

Another approach to accomplish this that we use is to create a very small workflow .net assembly that you simply pass the guid to and return it as a string and then build the html within the workflow rule itself.  It's a very simple couple of lines of code and doesn't add unnecessary fields to the database or have any issues with the creation of the record not filling the value in as mentioned above.  I agree it would be better to have this turned back on since this was possible in v1.x without any code.

C. Eakin wrote re: Embedding Direct Links To CRM In A Workflow Email
on 08-24-2007 2:08 PM

I'm glad I found this posting.  This is just what I need for my setup - thanks for sharing.

But... I'm encountering the challenge where my Email to Case automated process is not generating the URL.  I'm assuming the OnSave() process is run before it knows the ID.  If I open the case and then save it, it creates the URL just fine.  

If you guys have created a simple solution (other then an assembly), I would appricate it.

vbullinger wrote re: Embedding Direct Links To CRM In A Workflow Email
on 08-31-2007 12:23 PM

The assembly is the simple solution.  I've seen code for it in a million places.  It's VERY short and reusable across many applications.

Jaber wrote re: Embedding Direct Links To CRM In A Workflow Email
on 09-16-2007 11:31 PM

Excellent Work.

Mark wrote re: Embedding Direct Links To CRM In A Workflow Email
on 10-10-2007 3:49 PM

My workflow generates the url in the email, but there is no link, just text.  Why?

Mark wrote re: Embedding Direct Links To CRM In A Workflow Email
on 10-10-2007 3:50 PM

I meant just the URL text, but it is not highlighted.

Sarah Montgomery wrote re: Embedding Direct Links To CRM In A Workflow Email
on 10-20-2007 10:25 PM

Thanks for this post. It's a great adition to our Sales and Delivery processes. I do not have experience with Java, so your post makes our workflow processes actually effective!

Jeremy Winchell wrote re: Embedding Direct Links To CRM In A Workflow Email
on 10-23-2007 12:15 AM

Mark,

The first thing that I would check is what the format of the email body is in Outlook.  If the format is set to Rich Text the Url is not always highlighted in the body of the email.  If you change the format in Outlook from Rich Text to HTML, the Url should resolve and become an actual link within the body of the email.

Let me know how it turns out.

Jeremy

zxevil135 wrote re: Embedding Direct Links To CRM In A Workflow Email
on 02-29-2008 9:19 AM

l6LTUC r u crazzy? I told u! I can't read!

zxevil136 wrote re: Embedding Direct Links To CRM In A Workflow Email
on 03-01-2008 3:06 PM

JuzFlj r u crazzy? I told u! I can't read!

zxevil134 wrote re: Embedding Direct Links To CRM In A Workflow Email
on 03-06-2008 4:39 PM

6MdIkm r u crazzy? I told u! I can't read, man!

zxevil141 wrote re: Embedding Direct Links To CRM In A Workflow Email
on 03-06-2008 7:42 PM

7TNpsP r u crazzy? I told u! I can't read!

Sarah Montgomery wrote re: Embedding Direct Links To CRM In A Workflow Email
on 03-12-2008 9:42 AM

I found another great application for this URL script. It can export to MapPoint, and I can fake integration between CRM & MapPoint. Question: I have over 600 records to update with this URL data. Is there any way to update the records without opening each one individually?

I have discovered that if you create a new record, you have to save it TWICE (or refresh it) to make the URL populate (this makes sense to me). My problem with this is that the sales people create the record, save it, run a manual workflow, and the URL doesn't populate in that workflow's email UNLESS they save twice or close it and reopen. Know of a fix-it?

Jeremy Winchell wrote re: Embedding Direct Links To CRM In A Workflow Email
on 03-12-2008 12:41 PM

Sarah,

there are some flaws/drawbacks in the initial approach.  A workflow assembly is the best way to do it for new records.  However, the approach above will work for those records that already exist.

If you wanted to do a Bulk Update of this field I would write a .NET assembly that you can call from within a CRM 3.0 Workflow.  That is the approach I have started to take when implementing the solution above.

I should update this post and highlight the issues with it and how we can resolve it.

Let me know if you have any questions, I may be able to provide a quick code snippet.

Jeremy Winchell

Jonesy wrote re: Embedding Direct Links To CRM In A Workflow Email
on 03-14-2008 1:53 AM

Code Snipit would be great! :)

Jeremy Winchell wrote re: Embedding Direct Links To CRM In A Workflow Email
on 03-25-2008 12:52 PM

I'm in the process of writing version 2 of this blog post.  In that posting I will have code snippets on how to do this in CRM 3.0 and CRM 4.0.

Ben wrote re: Embedding Direct Links To CRM In A Workflow Email
on 04-24-2008 4:47 PM

Do you have any code snippets for doing this in 4.0

Craighton wrote re: Embedding Direct Links To CRM In A Workflow Email
on 05-02-2008 12:11 PM

It is not working for me.  I am trying to preview and run the code but it just exit out of crm?  Is the nvarchar suppose to be url type?

Jeremy Winchell wrote re: Embedding Direct Links To CRM In A Workflow Email
on 05-13-2008 6:52 PM

Ben - I am working on something similiar for 4.0.  Hopefully it will be published in the next couple of weeks.

Craighton - You could make it of type URL but it should render as a URL in the body of the e-mail once it's sent.  If you are trying to do it within the Form you may have IE set to open links in the same window as opposed to a new window.

Chie Ann wrote re: Embedding Direct Links To CRM In A Workflow Email
on 07-14-2008 3:33 AM

I tried doing this on 4.0 and it works too.

- I added a new attribute on lead named new_link;

- Added that attribute on the lead form on customization.

- On the onSave event of the lead i added this code

var objId;

var embedUrl;

if(crmForm.FormType != 1)

{

    objId = crmForm.ObjectId;

    embedUrl = "http://<CRM>/sfa/leads/edit.aspx?id=" + objId;                    

    crmForm.all.new_urllink.DataValue = embedUrl;

    crmForm.all.new_urllink.ForceSubmit = true;

}

- Then added "Lead(new_urllink)" to the body of the email on the workflow.

And it works.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Inetium, LLC. Disclaimer