Hyperlinks in Notifications

  • 3 January 2008
  • 9 replies
  • 8 views

Badge +3

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?


 


9 replies

Badge +10
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 ServerBin sub directory of the blackpearl install directory.
Badge +3

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.

Badge +11

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


 

Badge +8

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.

Badge +3
It's a custom class I created that uses regular expressions to convert URLs to hyperlinks.
Badge +2

Hello DavidL, 


I'm to new at K2 blackpearl and I need to create dynamic mails. You said that you have a simple example. Can you send me or explain me how to make that.


Thanks
Darko 

Badge +8

You can also have a look at the following inline function, it might do what you need:


http://www.k2underground.com/groups/email_template_inline_function/default.aspx

Badge +5

If I get you right, you just need to add a hyperlink in your email message, so that the users can click and load up the URL in browser?


Since you already have the URL in a DataField, you can use Text -> Hyperlink inline function to complete the task. I did a simple test and it fulfils the requirement.


Steps


1. Go to Event Notification Message


2. Open the Context Browser


3. Switch to the Function Browser tab.


4. Expand Text, drag and drop Hyperlink to the message body.


5. Fill in the Display Name and URL.


6. Save, deploy and test.


 


JK.


 

Badge +6

In the link below I have mentioned the workaround;
http://amankazi.wordpress.com/2013/02/07/k2worklistlinkinemail/


Thanks,
Aman

Reply