{"id":336,"date":"2014-02-26T00:14:18","date_gmt":"2014-02-25T18:14:18","guid":{"rendered":"http:\/\/markwheeler.com\/wordpress\/?p=336"},"modified":"2014-02-26T00:14:18","modified_gmt":"2014-02-25T18:14:18","slug":"ssis-package-to-send-email-based-on-sp-task-list-due-dates","status":"publish","type":"post","link":"https:\/\/markwheeler.com\/?p=336","title":{"rendered":"SSIS package to Send Email based on SP Task List Due Dates"},"content":{"rendered":"<p>Had a request to send notification emails against a SharePoint Task List when the Due Dates were 90, 60, 30 and 5 days out.<\/p>\n<p><a href=\"http:\/\/markwheeler.com\/wordpress\/wp-content\/uploads\/2014\/02\/SSISTasksDueList.jpg\"><img decoding=\"async\" alt=\"SSISTasksDueList\" src=\"http:\/\/markwheeler.com\/wordpress\/wp-content\/uploads\/2014\/02\/SSISTasksDueList.jpg\" \/><\/a><br \/>\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/markwheeler.com\/wordpress\/wp-content\/uploads\/2014\/02\/SSISTasksDue.jpg\" \/><br clear=\"all\" \/><br \/>\nSteps:<br \/>\n0. You will need to create the 6 variables show on the left.<\/p>\n<p>1. I am dropping and importing the SP List Data each time the package is run with<br \/>\na SQL Task.<\/p>\n<p>2. I am using the SharePoint adapter add-ins from codeplex.com<\/p>\n<p>3. The query to pull the data into SSIS is screenshot #1 below. Make sure your<br \/>\nResultSet is set to &#8220;Full Result Set&#8221;<\/p>\n<p>3a. Click on Result Set and set it to your global QueryResults variable.<br \/>\nScreenshot #2.<\/p>\n<p>4. Add a Foreach Loop Container. Use the Foreach ADO Enumerator and set the<br \/>\nADO Object to your global QueryResults variable. Screenshot #3<\/p>\n<p>4a. Set your variable mappings to your Item global variables. Screenshot #4.<\/p>\n<p>5. Add a Script Task with the code snippet below.<\/p>\n<p>6. Add a Send Email Task. Create your SMTP connection.<br \/>\nAdd a From email address.<br \/>\nSet MessageSourceType to Variable.<br \/>\nSet MessageSource to your global EmailBody variable.<br \/>\nScreenshot #5.<\/p>\n<p>7. Modify your Send Email Task Expressions setting the ToLine to your global<br \/>\nEmailBody variable. Important Note: Set the Delay Validation<br \/>\nproperty to True.<\/p>\n<p>8. Deploy and schedule your package.<\/p>\n<p>Screenshot #1<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/markwheeler.com\/wordpress\/wp-content\/uploads\/2014\/02\/SSISTasksDueSQLTask.jpg\" \/><br \/>\n<br clear=\"all\" \/><br \/>\nScreenshot #2:<\/p>\n<p><img decoding=\"async\" alt=\"SSISTasksDueSQLTask2\" src=\"http:\/\/markwheeler.com\/wordpress\/wp-content\/uploads\/2014\/02\/SSISTasksDueSQLTask2.jpg\" \/><br \/>\n<br clear=\"all\" \/><br \/>\nScreenshot #3:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/markwheeler.com\/wordpress\/wp-content\/uploads\/2014\/02\/SSISTasksDueForEach1.jpg\" \/><br \/>\n<br clear=\"all\" \/><br \/>\nScreenshot #4:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/markwheeler.com\/wordpress\/wp-content\/uploads\/2014\/02\/SSISTasksDueForEach2.jpg\" \/><br \/>\nScript Task Code:<\/p>\n<pre>\/*Microsoft SQL Server Integration Services Script Task\n   Write scripts using Microsoft Visual C# 2008.\n   The ScriptMain is the entry point class of the script.\n*\/\n\nusing System;\nusing System.Data;\nusing Microsoft.SqlServer.Dts.Runtime;\nusing System.Windows.Forms;\n\nnamespace ST_7f59d09774914001b60a99a90809d5c5.csproj\n{\n    [System.AddIn.AddIn(\"ScriptMain\", Version = \"1.0\", Publisher = \"\", Description = \"\")]\n    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase\n    {\n\n        #region VSTA generated code\n        enum ScriptResults\n        {\n            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,\n            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure\n        };\n        #endregion\n\n        public void Main()\n        {\n            Variables varCollection = null;\n            string header = string.Empty;\n            string message = string.Empty;\n\n            Dts.VariableDispenser.LockForWrite(\"User::EmailBody\");\n            Dts.VariableDispenser.LockForWrite(\"User::ItemTitle\");\n            Dts.VariableDispenser.LockForWrite(\"User::ItemDue\");\n            Dts.VariableDispenser.LockForWrite(\"User::ItemEmail\");\n            Dts.VariableDispenser.LockForWrite(\"User::DaysOut\");\n            Dts.VariableDispenser.GetVariables(ref varCollection);\n\n            \/\/Set the header message for the query result\n            if (varCollection[\"User::EmailBody\"].Value == string.Empty)\n            {\n                header = \"You have been assigned a task:nn\";\n\n                varCollection[\"User::EmailBody\"].Value = header;\n            }\n            \/\/Clear previous message is applicable\n\n           \/\/Create Body \n            message = \"The due date for this task is \"+varCollection[\"User::ItemDue\"].Value+\"nnThis task is \"+varCollection[\"User::DaysOut\"].Value+\" days out from the due date. nn\";\n\n            varCollection[\"User::EmailBody\"].Value = varCollection[\"User::EmailBody\"].Value + message;\n\n            Dts.TaskResult = (int)ScriptResults.Success;\n        }\n    }\n}<\/pre>\n<p>Screenshot #5:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/markwheeler.com\/wordpress\/wp-content\/uploads\/2014\/02\/SSISTasksDueSendemail.jpg\" \/><br \/>\n<br clear=\"all\" \/><br \/>\nScreenshot #6:<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"http:\/\/markwheeler.com\/wordpress\/wp-content\/uploads\/2014\/02\/SSISTasksDueSendemail2.jpg\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Had a request to send notification emails against a SharePoint Task List when the Due Dates were 90, 60, 30 and 5 days out. Steps: 0. You will need to create the 6 variables show on the left. 1. I am dropping and importing the SP List Data each time [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[2,10,11],"tags":[110],"class_list":["post-336","post","type-post","status-publish","format-standard","hentry","category-computer","category-sharepoint","category-software","tag-ssis"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336"}],"version-history":[{"count":0,"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/336\/revisions"}],"wp:attachment":[{"href":"https:\/\/markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}