Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I had a question about how to get this going: - I have emails being sent out that include a link to the task form. However right now, the previous task from is in the email. How can I make it such that the approver recieves an email to approve in the task form

  • I don't have extensive knowledge of progmatticaly making such changes, so please bear with me

Thanks!

private string TaskUrl 
    {
        get
        { 
            return workflowProperties.WebUrl + "/_layouts/WrkTaskIP.aspx?List=" + workflowProperties.TaskListId.ToString() + "&ID=" + createTask1_ListItemId2.ToString() + "&Source=" + workflowProperties.WebUrl;
        }
    }

    //added 08/18/2012 by Mariano
    private string FormUrl 
    {
        get 
        {
            string formUrl = string.Empty;

            using (SPSite site = workflowProperties.Site)
            {
                using (SPWeb web = site.OpenWeb(workflowProperties.WebId))
                {
                    formUrl = web.Url + "/_layouts/FormServer.aspx?";
                    SPList requestsList = web.GetList(workflowProperties.Item.Fields["Path"].GetFieldValueAsText(workflowProperties.Item["Path"]));
                    formUrl = formUrl + "XmlLocation=" + requestsList.RootFolder.ServerRelativeUrl + "/" + workflowProperties.Item.Name;
                    formUrl = formUrl + "&Source=" + workflowProperties.ListUrl + "&DefaultItemOpen=1";
                }
            }

            return formUrl;
        }

}

try {
            using (SPSite site = workflowProperties.Site) {
                using (SPWeb web = workflowProperties.Web) {

                    SPList requestsList = web.GetList(workflowProperties.Item.Fields["Path"].GetFieldValueAsText(workflowProperties.Item["Path"]));
                    debugMsg("in onWorkflowActivated1_Invoked(), created SPList requestsList=" + requestsList.Title.ToString());

                    SPListItem request = requestsList.Items[this._requestGUID];

                    this._requestURL = request.Fields["Encoded Absolute URL"].GetFieldValueAsText(request["Encoded Absolute URL"]);

                    //if (configBool("debug")) {
                    //    foreach (SPField f in request.Fields)
                    //        debugMsg("request.fields[" + f.Title + "]='" + f.GetFieldValueAsText(request[f.Title]) + "'");

                    //    foreach (DictionaryEntry de in request.Properties)
                    //        debugMsg("request.properties[" + de.Key.ToString() + "]='" + de.Value.ToString() + "'");
                    //}
                    web.Close();
                    web.Dispose();
                }
                site.Close();
                site.Dispose();
            }
string formUrl = string.Empty;
        try {
            string departmentName = "";
            ArrayList departmentApprovers = new ArrayList();
            bool shouldNotify = false;

            using (SPSite site = workflowProperties.Site) {
                using (SPWeb web = workflowProperties.Web) {
                    formUrl = web.Url + "/_layouts/FormServer.aspx?";
                    SPList requestsList = web.GetList(workflowProperties.Item.Fields["Path"].GetFieldValueAsText(workflowProperties.Item["Path"]));
                    debugMsg("in notifyDepartmentApprover(), created SPList requestsList=" + requestsList.Title.ToString());
                    formUrl = formUrl + "XmlLocation=" + requestsList.RootFolder.ServerRelativeUrl + "/" + workflowProperties.Item.Name;
                    formUrl = formUrl + "&Source=" + workflowProperties.ListUrl + "&DefaultItemOpen=1";
                    SPListItem request = requestsList.Items[this._requestGUID];

                    if (configBool("deptPropertyByGUID")) {
                        departmentName = request.Fields[configGUID("propertyDeptGUID")].GetFieldValueAsText(request[configGUID("propertyDeptGUID")]);
                    } else {
                        departmentName = request.Fields[configString("propertyDeptName")].GetFieldValueAsText(request[configString("propertyDeptName")]);
                    }
                    debugMsg("in notifyDepartmentApprover(), got departmentName=" + departmentName);

                    // get approver for that department from Departments list:
                    SPList departmentsList = web.Lists["Departments"];
                    debugMsg("in notifyDepartmentApprover(), created SPList departmentsList=" + departmentsList.Title.ToString());

                    SPListItemCollection departments = departmentsList.Items;
                    int x = 0;
                    bool found = false;
                    while ((x < departments.Count) && !found) {
                        debugMsg("Looping through Departments items, iteration #" + x.ToString());
                        if (departments[x]["Title"].ToString() == departmentName) {
                            debugMsg("found department '" + departmentName + "' at index " + x.ToString());
                            SPFieldUserValueCollection apprvrs = new SPFieldUserValueCollection(web, departments[x]["Approver"].ToString());
                            for (int y = 0; y < apprvrs.Count; y++) {
                                if (apprvrs[y].User != null)
                                    departmentApprovers.Add(apprvrs[y].User.Email);
                            }

                            if (departments[x].Fields["Notify"].GetFieldValueAsText(departments[x]["Notify"]) == "Yes")
                                shouldNotify = true;

                            found = true;
                        }
                        x++;
                    }
                    web.Close();
                    web.Dispose();
                }
                site.Close();
                site.Dispose();
            }


            // send email to Departmental and First approver:
            if (shouldNotify && (departmentApprovers.Count != 0)) {
                System.Net.Mail.MailMessage mess = new System.Net.Mail.MailMessage();
                debugMsg("Created MailMessage 'mess'");
                for (int x = 0; x < departmentApprovers.Count; x++) {
                    mess.To.Add(departmentApprovers[x].ToString());
                }
                if (configBool("ccEnable"))
                    mess.CC.Add(configString("ccAddress"));
                System.Net.Mail.MailAddress firstApproverEmail = new System.Net.Mail.MailAddress(getApproverEmail(1));
                mess.From = firstApproverEmail;
                mess.CC.Add(firstApproverEmail);
                mess.Subject = "Capital Project Request created for '" + departmentName + "'";
                mess.IsBodyHtml = true;
                mess.Body = "A new Capital Project Request has been created for your department/location, '" + departmentName + "', and submitted for approval.<br /><br /><a href='" + this.FormUrl + "'>Open Capital Project Request</a><br /><br /><a href='" + this.TaskUrl + "'>Open Task Form</a><br /><br /><br />Please review this request and reply to " + GetApprover(1, true) + " with your comments.<br /><br />This is message was sent automatically on behalf of " + GetApprover(1);

                debugMsg("MailMessage 'mess' has been populated");
                System.Net.Mail.SmtpClient emailClient = new System.Net.Mail.SmtpClient(configString("smtpServer"));
                emailClient.Send(mess);
                debugMsg("MailMessage 'mess' has been sent");
            } else {
                success = false;
                if (shouldNotify)
                    debugMsg("Error, couldn't find departmental approver for Department/Location '" + departmentName + "'. Will not attempt to send Departmental Approval email.");
            }
share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.