Email Test Form and Email Logic Control with Server Side Scripts
This is a sample procedure that has 2 parts:
1) An admin form that allows you to test emailing functionality visually.
2) Server side logic that controls all the emailing for a process based on action name/stage name you pass. All you have to do is call the script from an action/stage event.
Also included stored procedure to creates line item for emails in a group. Some of the code used is below.
Edit for code cleanup
Stored Procedure for group email
CREATE PROCEDURE [dbo].[sp_BuildGroupEmails] @EmailGroup nvarchar(500) AS BEGIN Declare @Emails nvarchar(2000) SELECT @Emails = coalesce(@Emails + '; ', '') + eEMailAddress FROM eUser WHERE eUserName IN ( SELECT eUserName FROM eAssignment WHERE eRoleName = @EmailGroup) SELECT @Emails END
Call email script from Action/Stage
//Calls code to manage email and adds to notes ProcessContext.ActionNote = EmailScripts.SendEmails(ProcessContext.ActionName, ProcessContext.FolderId )
Server Side Call to Send Email
The only thing you really need to do here is set the default values and the Case logic info
[Promote(PromotionTargets.ExpressionBuilder)] [Category("Communication")] [Alias("Email Functions")] [Description("Send Email")] public static Metastorm.Runtime.Types.Text SendEmails ( [Alias("Action Name")] [Description("the name of the stage/action")] Text action, [Alias("FolderID")] [Description("processcontext folderid")] Text folderid ) { //set defaul variables string sendto = "<target user email>"; string sendcc = ""; string sendbcc = ""; string attachment = ""; string sendfrom = "<metastorm server email>"; string subject = "Test Subject"; string weblink = "<a href='<metastorm server url>'>Go to Metastorm System</a>"; string folderlink = "<a href='<metstorm server url>/metastorm/eFolder.aspx?FolderID=" + folderid + "&Client=External'>Go to Folder</a>"; //build email body string messageheader = ""; string message = "<pre>" + "<br> <b><u>Access</u></b>" + "<br> <b>Web Link:</b> " + weblink + "<br> <b>Folder Link:</b> " + folderlink + "<div align='center'><b><i>NOTE: This email was generated by Metastorm. Please do not reply.</i></b></div>"; switch (action.ToString().ToLower()) { case "createtestemail": messageheader = "Created a test email"; //sendto = ""; break; case "entry": messageheader = "New request has been submitted"; //sendto = ""; break; case "archive": messageheader = "Request sas been archived"; //sendto = ""; break; default: messageheader = "Metastorm notification"; //sendto = ""; break; } message = messageheader + "<br><br>" + message; return "Email Notification Sent To: " + sendto + " " + Mstm.SendEmail(sendto, sendcc, sendbcc, subject, message, attachment, sendfrom).ToString(); }
Well it works but always room for improvements. Enjoy.
Comments
-
You don't need to pass in the folder information - it can be gathered from a processContext object.
As you probably don't need the return, it may be more useful to add an option to use as a Visual Script activity.
0 -
Jerome,
Thanks for the input! For some reason it didn't even cross my mind to utilize processContext to get the folderid. I'll have to make that change. Cheers!
0
Categories
- All Categories
- 123 Developer Announcements
- 54 Articles
- 155 General Questions
- 149 Thrust Services
- 57 Developer Hackathon
- 37 Thrust Studio
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 918 Core Messaging
- 84 Digital Asset Management
- 9.4K Documentum
- 33 eDOCS
- 190 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 10 XM Fax
- Follow Categories