eXTReMe Tracker

Monday, September 8, 2008

Formatting email content - BPEL Email activity

I had this requirement in BPEL to email a certain group incase of any errors in a BPEL process.We could achieve this
using a simple Email activity in BPEL. But, my client wanted me to send the notification in a formatted way, such as:

The following error has occurred in XX process:
------------------------------------------------
Error Code:XX
Error Message:XXXX
------------------------------------------------
Please check the following instance for more information:
http:\\link_for_the_instance
------------------------------------------------

The problem with the above format is that is has new line characters in between. I came across somewhere that we can insert new line using "& # 13 ; "(no spaces). It's the character to insert newline in XML payload. But it never worked.

Then I found from Dharmendra Dubey's blog that JDeveloper changes "
& # 13 ;" to "amp # 13 ; "(no spaces). So I went to the source view and edited 'amp' back to '& '. But still, I wasn't able to get the new line character in my payload.

Then I figured out that we need to change the MimeType from 'text/html' to 'text/plain' to make this whole damn thing work.

Furthermore, I wanted the link for the instance to be dynamic. So, I have used getdomainId(),getProcessId(),getProcessVersion() and getinstanceId() functions to prepare the link and concatenated it to my content body.

Voila..Your email with formatted body is ready..but it is in plain text and what that means is that you can't have colors and etc..

Now, lets look at the other option which is 'html'. You can write simple HTML code to groom the message
as nicer as you want and use that in 'Email' acitivity of the BPEL.
For example, here's a simple piece of HTML code to insert a newline and also to play with the font sizes and colors:

<FONT SIZE=4
>
Here is the message:<br>

</FONT>
<FONT SIZE=2 >
<B>
Message Text Here
<HR ALIGN=LEFT>
</FONT>

Just copy and paste the above code in the content portion of your 'Email' actitivity and modify it as you wish to send a notification
with different fonts, colors and what not.




1 comment:

Unknown said...

Hi,

Thanks a lot, it really helped me...!!
i have query, if you can help me on this.
My requirement is as follows:

1) I am reading the DB table for errors.
2) According to the number of erros, i have to format it in html format and send it as an email to the user.
3) If i have four fields which i have to pass in email. When there is a single set it is working fine with, because i am doing a concat with 'bpws:getVariableData'.
4) The problem is when i have a multiple sets then i have to use for-each, but in html it is not reading the values.

can you suggest something.