Edit E-mail before sending it through workflow

By | August 30, 2010

There is Send email workflow action provided for this under standard workflow. This functionality is quite efficient for email sending if no complicated e-mail design is involved.

We were requested the twist in this e-mail sending functionality for one of the custom entities on our client’s Sage CRM system. Though the entity was custom primary entity, to avoid discrepancies in merging process initially we designed the email sending and merging script in table level script for that entity. The script was reading the template design and then merge it manually to get the final HTML string to be sent in an e-mail. This script was forced to run as soon as the status of that entity is set to Active through workflow. The functionality was to send welcome letter to client as soon as Project becomes Active in CRM through workflow. Here Project is the custom entity in discussion. The new requirement from our client stated that the email requires being editable before sending it to client so that any changes can be made to contents at last moment.

I searched through Sage CRM blogs and forums to look for any guidance in this regards and arrived at the conclusion that I may need to design the entire e-mail editing screen manually. The fact that we can call CustomPages on Workflow rule and still not able to use standard behavior was still tickling in my mind.

I started off with scratch and called a Custom Page on my workflow rule. On this page I designed the usual progress screen with new status being set and the Comment box with Save and Cancel buttons.

Now on this page I created my URL to standard e-mail editing screen i.e.”eWare.URL (1500)”. Then I added one more parameter to this URL to represent id of the template to be used in email body.

This got me to an e-mail screen. Now what next? I have a template id with me in URL. There is a communication detail screen at the bottom of email editing screen.

On this screen from client side scripting I added an IFRAME. Now as per the standard behavior if I will set the template id in Template selection field on this screen, it fires the on change function and loads the page again with template selected in email body. As I had the template id with me I set the same in Template selection field and called on change event manually from client side. This got me the required template in body.

The email body that we see on screen is the field named “edit”. From the iframe window I read the contents of this field on parent window and replaced it with the merged contents to get the new email content to be sent to client. As now I have the new merged content, I can set it in field on parent window. Did the same from client side scripting and guess what I can see my merged email content available for editing before being sent out to client. Isn’t it interesting?
Now here the good thing is, if email is sent through Send E-mail button we are again redirected back to our custom page from where we redirected to this action URL. Keeping track of this we can manually progress our workflow for that entity record.

One more thing we may need to take care is to send one more parameter in URL to indicate that the e-mail screen is being opened through workflow. Using this flag we can handle the actions on screen as explained above.

Note: Please click on images to enlarge them.

If you find this content useful, please feel free to drop us an email at crm@greytrix.com.