Hyperlinks in Notifications

Last post 05-21-2008, 11:58 AM by RMillar. 5 replies.
Sort Posts: Previous Next
  •  01-03-2008, 11:57 AM 20860

    Hyperlinks in Notifications

    I'm trying to include hyperlinks in my k2 mail events.  The number one reason we're struggling with k2 adoption is people currently have to copy and paste URLs from k2 notifications to their browsers.  Since the html wysiwyg lacks any real html capabilities, I'm trying to find a simple workaround. 

    I started by trying to create a hyperlink within a data field and including the field within the email body.  However, data fields are HTML encoded, so that didn't work.  It's also worth noting that data fields are html encoded, but line breaks aren't replaced by html breaks (<br/>).  So, that is also part of my goal here. 

    Next, I tried using a regular expression to replace URLs with hyperlinks in the code behind.  That didn't work because I was dynamically creating the URL within the email body.  For example, I was using a URL data field and appending the process instance ID to the query string.  The problem is that each field is wrapped in span tags, so my regular expression wasn't picking up the process instance ID on the URL.

    My solution now is to use a server event to construct the URL in a single datafield.  Then I include the datafield in the email body.  In the code behind, I use my regular expression to automatically convert URLs to hyperlinks and convert line breaks to HTML line breaks.

    My two questions:

    1) Does anyone have a simpler solution?

    2) Is there a way to add my code to the default generated mail event code so I don't have to manually add my code every time?

     

  •  01-03-2008, 12:28 PM 20862 in reply to 20860

    Re: Hyperlinks in Notifications

    Not sure about the first part but i will try it.  As far as 2...Take a look at the SourceCode.EventBus.ClientRecorder.DLL.mailTemplate file in the Host Server\Bin sub directory of the blackpearl install directory.
  •  01-03-2008, 3:44 PM 20867 in reply to 20862

    Re: Hyperlinks in Notifications

    I believe the SourceCode.EventBus.ClientRecorder.DLL.mailTemplate is only used with notification events.  Correct me if I'm wrong, but the Notification Events are at the server level and cannot be deployed between servers.  I need something at the process level that can be deployed between environments. 

    I'm hoping there is a way to get at the default code for a Mail Event, when you right click the event > View Code > Event Item.  Then you can edit the code behind SendMail.  I just changed the following line:

    this.EmailMessage.Body = K2.Configuration.Body;

    to

    this.EmailMessage.Body = (bool.Parse(K2.Configuration.HTMLEmail))? K2Notifications.FormatHTMLNotification(K2.Configuration.Body) : K2.Configuration.Body;

    on the SetProperties_ExecuteCode method.

    I see some default code in the WebWorkflow.dbo.ProcessCode for the SendMail event.  I'm wondering if there is something similar in a local file for Visual Studio.

  •  01-03-2008, 6:27 PM 20869 in reply to 20860

    Re: Hyperlinks in Notifications

    I have a couple of ideas for you. 

    First, I would look at custom notifications.  You can write a simple .NET assembly to implement your custom email code and then in workspace execute a method in this assembly in response to many different events.  This allows you to administratively configure the emails without re-deploying the workflow.  I have a very simple example of a custom notification I can send you if you need it.

    Second, there is a whitepaper on our customer portal on how to create your own wizard that you can add to the Visual Studio toolbox in the workflow designer.  It's straightforward, but a little more difficult than creating the custom notification.  This would allow you to drag your custom event on to the design canvas whenever you need it. 

    Lastly, yes, you can change the default code for the mail event.  Although very easy, I would save this as a last resort.  When we deliver any future service packs, your changes to the template would likely be overwritten.  You would have to make a copy (always a good idea) and then put your copy back after the service pack.  Also, if you make a change to a template and introduce a bug, it would be difficult for our helpdesk to figure out.  If you locate the whitepaper on how to create your own wizard, it will be obvious how the code templates work and how you can change the OOTB templates.  If you want more info on this, send me an email.

    David

     


    The statements and opinions made in my postings are my own, and do not reflect the opinions of SourceCode Technology Holdings, Inc. or its subsidiaries. All information is provided as is with no warranties, express or implied, and grants no rights or licenses.
    Filed under:
  •  03-28-2008, 7:14 AM 22793 in reply to 20867

    Re: Hyperlinks in Notifications

    Where did you get the "K2Notifications" class from? I can't find it :(

    I think about creating a custom event but first I'd like to test this little change.


    Please remember to change the thread status when a valid answer has been given
  •  05-21-2008, 11:58 AM 23943 in reply to 22793

    Re: Hyperlinks in Notifications

    It's a custom class I created that uses regular expressions to convert URLs to hyperlinks.
View as RSS news feed in XML