vrijdag 6 juli 2012

SP2010 Sequential Workflow Send Email

Send Email in a sequential workflow


Create a Send Email task activity on your workflow.

Don't forget to set the CorrelationToken to the same token as your workflow! See earlier post. 

The code behind of that task is:

SPUser siteOwner = IntranetUtility.GetSPUser(currentItem, IntranetFieldId.SiteRequest.SiteOwner);
SPUser siteBackupOwner = IntranetUtility.GetSPUser(currentItem, IntranetFieldId.SiteRequest.SiteBackupOwner);

SendEmail confirmationMail = (SendEmail)sender;
confirmationMail.To = siteOwner.Email + ";" + siteBackupOwner.Email;
confirmationMail.Subject = string.Format("Your site {0} is created", currentItem.Title);
confirmationMail.Body = "Link to created site";
 
SPUtility.SendEmail(workflowProperties.Web, true, false, confirmationMail.To, confirmationMail.Subject, confirmationMail.Body);

SP2010: Sequential Workflow Correlation Token SendEmail

Workflow Foundation Correlation Token error

Within a workflow that I was developing, there was a requirement to notify a group of SharePoint users that a lookup service had failed. This particular activity was within a parallel activity sequence. I chose to use the SendEmail activity to notify the users, but incorrectly set the Correlation Token to a new value. When testing this functionality in the workflow I received an error:

SharePoint LOG
  1. WinWF Internal Error, terminating workflow Id#
  2. System.InvalidOperationException: Correlation value has not been initialized on declaration emailToken_JobNumberCreate for activity sendEmail_JobNumberNotCreated. at System.Workflow.Activities.CorrelationService.InvalidateCorrelationToken

The correct Correlation Token for a SendMail Activity is the “Workflow” token. The reason, which is fairly obvious, is that the SendEmail activity maps to the workflow, not to a task, which would require a Task Token