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

Comments (14)

  1. John says:

    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.

  2. Shashi Ranjan says:

    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

  3. Ray says:

    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.

  4. Kevin says:

    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?

  5. sranjan says:

    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"/>

  6. Dimitris Foukas says:

    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  

  7. Miki says:

    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)

  8. Irena says:

    change this in your assembly

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

  9. 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

  10. Bahram Aziz says:

    I created a custom assembly and compiled.

    I also registered the custom assembly in the C:Program FilesMicrosoft CRMServerbinassemblyworkflow.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.

  11. Bahram Aziz says:

    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;

    }

      }

    }

  12. Osvaldo says:

    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.

  13. TKS says:

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

  14. Satya says:

    yes. Custom workflow activities and plugins are not possible to register on Microsoft CRM online.

Skip to main content