Welcome to MSDN Blogs Sign in | Join | Help

Adding CRM URLs to E-mail Messages Sent Via Workflow

One of the task that workflow proves very handy is in sending email reminders when tasks are due. To improve the user experience it will be great if we can send the link to the crm entity instance that is due in the email so that users can select the link and go directly to the entity instance and start working on it.

You will have to do the following to enable this functionality.

  1. Create a small custom assembly that concatenates a string and GUID.
  2. Register the assembly in workflow config file.
  3. Create a workflow rule to send email reminders.
  4. Activate the workflow rule and you are good to go.


Step 1: Creating the custom assembly.

public string ConstructLink(string baseUrl, Guid objectId)

      {

            return baseUrl + objectId.ToString("B");

      }

Compile the funtion to an assembly file. Say workflowtestassembly.dll and let the class name be HelloType.

Step 2: Register the custom assembly in file workflow.config.

<method name="ConstructLink" assembly="workflowtestassembly.dll" typename="HelloType" methodname="ConstructLink" group="Link">

      <parameter name="baseUrl" datatype="string"/>

      <parameter name="objectId" datatype="lookup" entityname="task"/>

<result datatype="string"/>

      </method>

Step 3: Create a workflow rule.

When Task is created

Wait for 30 min before Task.Due date

ConstructLink: TaskLink

Email To:[owner] Subject: Task is due.

Note: in the custom assembly action Construct link we pass the baseUrl for the task detail page. I.e. http://<servername:portnumber>/activities/task/edit.aspx?id=

For second parameter we pass the object id of the task. This can be done by selecting task in the dynamic value. The object id will be passed to the assembly as GUID.

The return value will look some similar to:
http://MyServer/activities/task/edit.aspx?id={D02787BE-6E31-DB11-95BE-0013720EC2DB}

Use the return value of the assembly within the email body via slugs. On the right to the email body on the email form in workflow manager you will see the slug button.

You can write text like.

“ Your task with subject: {!Task.Subject:} is due on {!Task.Due date:} . click the following link to look and update it. Link {!TaskLink:} “

Step 4:  Activate the workflow rule and test it out.

Shashi Ranjan

Published Wednesday, October 04, 2006 7:26 AM by crmblog

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

Can you provide a good source for info on creating custom assemblies like this in CRM? I tried using VS2005 to create this dll but I got compile errors. I think I'm missing something.
Friday, October 06, 2006 4:51 PM by John

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

I just gave the method. The actual file will contain code like blow. The project should generate a dll. and Also you will have to provide a full qualified name of the class in the type name in registration. using System; namespace CRMTest { public class HelloType { public string ConstructLink(string baseUrl, Guid objectId) { return baseUrl + objectId.ToString("B"); } } } Registration would look like
Friday, October 06, 2006 8:03 PM by Shashi Ranjan

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

I believe the reason that this code wouldn't compile for you in VS2005 is that workflow assemblies need to be .net 1.1 and vs2005 defaults to .net 2. I've seen blog entries describing how to make vs2005 use .net 1.1 if you can't/don't want to use vs2003.
Saturday, October 07, 2006 9:59 PM by Ray

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

Great post, I'm trying this out with a custom assembly and I can't get the entity to show up as the second dynamic value in the construct link (just get a blank drop down).  It works fine if I use it with a native type (i.e. Task).  Any thoughts on how to resolve this?

Thursday, October 12, 2006 7:57 PM by Kevin

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

Hey, it works only for the task because thats the entity name that is provided in the workflow config file registration. You will need to add multiple method section to enable for other entities just replace the entityname in the object id parameter. say for account

<parameter name="objectId" datatype="lookup" entityname="account"/>

Saturday, November 18, 2006 3:52 AM by Shashi Ranjan

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

I am starting to get my hands on MSCRM 3.0 workflow and these kind of posts are valuable to me. Thank you very much Shashi.

Two remarks/suggestions for improvement before proceeding:

1- IMO, the fact that we have to resort to extensions for such rudimentary tasks is a manifestation of severe limitations of the email templating engine...

2- Although our ConstructLink method is polymorphic, the configuration of the wflow assemblies is really more strongly typed than necessary resulting in redundant entries...

Now, the question: I am trying  to insert a hyperlink for the link  by formatting the template inside VS2005 and then cut & pasting into the workflow manager without any success. I am not using any email templates since I want to apply this action to a custom entity for which this is not an option.

Any tips?

Dimitris  

Monday, November 20, 2006 6:08 AM by Dimitris Foukas

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

Did anyone test it? , the workflow service send the email as a plain text, how can you make the url look as a link - (the only choice for the user is to copy the link to the browser and navigate)

Friday, November 24, 2006 5:35 AM by Miki

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

change this in your assembly

Return "<a href=" & baseUrl + objectId.ToString("B") & ">" & baseUrl + objectId.ToString("B") & "</a>"

Tuesday, December 12, 2006 6:02 AM by Irena

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

Hi,

I used the above code, but when i run the workflow, i get the error that typename "HelloType" can not be find in assembly Workflowassemblies.dll.

My code is

Imports System

Namespace CRMTest

   Public Class HelloType

       Public Function ConstructLink(ByVal baseUrl As String, ByVal objectId As Guid) As String

           Return "<a href=" & baseUrl + objectId.ToString("B") & ">" & baseUrl + objectId.ToString("B") & "</a>"

       End Function

   End Class

End Namespace

What am i doing wrong? Please help.

Thanks,

Ashwani

Saturday, March 17, 2007 12:55 AM by Ashwani Raghav

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

I created a custom assembly and compiled.

I also registered the custom assembly in the C:\Program Files\Microsoft CRM\Server\bin\assembly\workflow.config file.

I also created a workflow rule to test this but I keep getting this Access Denied message in the workflow monitor.

Fail Error Code = 80070005 Access Denied. You do not have suffieint access rights or permissions to perform this acction.

why do I get this message. Is there something I left out ot forgot.

Monday, April 30, 2007 1:11 PM by Bahram Aziz

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

This code is provided as-is

Network Infrastructure Tecjnologies. Inc.

NIT Connect

http://www.nitconnect.com

using System;

using System.Diagnostics;

using System.IO;

using System.Text;

using System.Xml;

// csc  /target:library /optimize+ /nologo  /out:MyAssembly.dll MyAssembly.cs

namespace NIT.Workflow.Assem

{

public class MyAssembly

{

       public MyAssembly()

       {

       }

public string ConstructLink(string baseUrl, Guid objectId)

{

           String url = baseUrl + objectId.ToString("B");

           String link = "<a href=\"" + url + "\">Link to Case</a>";

           return link;

}

  }

}

Monday, April 30, 2007 11:23 PM by Bahram Aziz

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

Hi, I followed each single step for this exercise, but the email message is not build correctly.

When I insert the slug subject this shows like this:

<a href=http://london:5555/activities/task/edit.aspx?id={30693c3a-0404-dc11-8aff-0003ff12adb4}>Esta es la liga</a>  

Note: after href the URL is include.

BUT, when the same slog is inserted on the body:

<a href=>Esta es la liga</a></pre>

Note: the URL is NOT included.

Can someone help me.

Thanks.

Wednesday, May 16, 2007 7:22 PM by Osvaldo

# re: Adding CRM URLs to E-mail Messages Sent Via Workflow

yeah, what if we are working with CRM Online? can't do any of this there right?

Wednesday, August 20, 2008 6:20 PM by TKS

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker