0

My task List has the Following Fields

1) Start Date
2) Due Date
3) Survey Submitted By

Through Visual Studio Workflows I want to achieve the below scenario. Can any one give me an idea which actions should I use.

Note: Here Task is Already assigned in the Task list. On Workflow Activated I need to fetch the Task item and send an email and do the below step again.

  1. Send an email to the Survey Submitted By (user) when the task is created.

  2. Send an email to the Survey Submitted By (user) when the task is a week from the Due Date (if the task is not completed)

  3. Send an email to the Survey Submitted By (user) when the task is two days from the Due Date (if the task is not completed)

  4. Send an email to the Survey Submitted By (user) on the Due Date (if the task is not completed)

  5. Mark the Task as "Not Completed" and remove the Survey Submitted By’s (user) permissions when the task is past the Due Date and Not Completed


Below is the scenario which I tried.

Workflow Designer:Workflow sample OnWorkflowActivatedCode:

  private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
        {
            try
            {


                CurrentDate = String.Format("{0:MM/dd/yyyy}", CTDate);
                SPListItem CurrentWorkflowitem = onWorkflowActivated1.WorkflowProperties.Item;
                _ItemListDuedate = DateTime.Parse(Convert.ToString(CurrentWorkflowitem["Due Date"]));
                _ItemSurveySubmittedBy = Convert.ToString(CurrentWorkflowitem["Survey Submitted By"]);
                _ItemStatus = Convert.ToString(workflowProperties.Item["Status"]);
                SPFieldUserValue SubmitteduserValue = new SPFieldUserValue(CurrentWorkflowitem.Web, _ItemSurveySubmittedBy);
                SubmittedUserLastName = SubmitteduserValue.User.Name.Split(',').LastOrDefault();
                SubmittedUserEmail = SubmitteduserValue.User.Email;              
            }

            catch (Exception ex)
            {

                SendEmailToAdmin(ex.Message);
            }

        }

WORKFLOW STATUS LOOP:

private void WorkflowStatus_Loop(object sender, ConditionalEventArgs e)
        {
           bool workflowstatus= CompareCurrentDate_DueDate(_ItemStatus, _ItemListDuedate);
           if (workflowstatus)
           {
               e.Result = true;
           }
 private bool CompareCurrentDate_DueDate(String CurrentStatus, DateTime ListDuedate)
        {
            try
            {
                if (CurrentStatus != "Completed")
                {
                    CTDate = DateTime.Parse(Convert.ToString(DateTime.Now));
                    int Cmin = CTDate.Minute;
                    int Listmin = ListDuedate.Minute;
                    diff = Cmin - Listmin;
                    //TimeSpan age = ListDueDate.Subtract(CTDate);
                    // diff = Convert.ToInt32(age.Days);
                    if (diff > 48)
                    {
                        datechk = false;

                    }
                }
                else
                {
                    datechk = false;
                }

            }
            catch (Exception ex)
            {
                datechk = false;
                SendEmailToAdmin(ex.Message);

            }
            return datechk;
        }}

Code to check Status 
 private void codeToCheckStatus_Initial(object sender, EventArgs e)
        {
            try
            {


                String Duedate = String.Format("{0:MM/dd/yyyy}", _ItemListDuedate);
                Remainder1 = (Boolean)onWorkflowActivated1.WorkflowProperties.Item["Remainder1"];
                Remainder2 = (Boolean)onWorkflowActivated1.WorkflowProperties.Item["Remainder2"];
                Remainder3 = (Boolean)onWorkflowActivated1.WorkflowProperties.Item["Remainder3"];
                InitialMail = (Boolean)onWorkflowActivated1.WorkflowProperties.Item["InitialMail"];

                if (InitialMail == true)
                {
                    Email_Body = "Please complete the below survey before the Due date has completed. ";
                    Email_Subject = "Survey Task with Title " + onWorkflowActivated1.WorkflowProperties.Item.Title + "has been assigned";
                    HTMLBODY = PopulateBody(SubmittedUserLastName, Duedate, Email_Body, "TaskList");
                    SendEmail(Email_Subject, SubmittedUserEmail, " ", HTMLBODY);
                    updatelist("InitialMail", false);
                }
                if (diff == 41 && Remainder1 == true)
                {
                    Email_Subject = "Week Remainder Email for the Task " + workflowProperties.Item.Title;
                    Email_Body = "The Task is due kindly act on it";
                    HTMLBODY = PopulateBody(SubmittedUserLastName, Duedate, Email_Body, "TaskList");
                    SendEmail(Email_Subject, SubmittedUserEmail, " ", HTMLBODY);
                    updatelist("Remainder1", false);

                }
                if (diff == 44 && Remainder2 == true)
                {
                    Email_Subject = "Two Day Remainder Email for the Task " + workflowProperties.Item.Title;
                    Email_Body = "The Task is due kindly act on it";
                    HTMLBODY = PopulateBody(SubmittedUserLastName, Duedate, Email_Body, "TaskList");
                    SendEmail(Email_Subject, SubmittedUserEmail, " ", HTMLBODY);
                    updatelist("Remainder2", false);

                }
                if (diff == 45 && Remainder3 == true)
                {

                    Email_Subject = "Same Day Remainder Email for the Task " + workflowProperties.Item.Title;
                    Email_Body = "The Task has been update as completed and you dont have permissions for the same";
                    HTMLBODY = PopulateBody(SubmittedUserLastName, Duedate, Email_Body, "TaskList");
                    SendEmail(Email_Subject, SubmittedUserEmail, " ", HTMLBODY);
                    //SPListItem wfitem = workflowProperties.Item;
                    //wfitem["Remainder3"] = false;
                    //wfitem["Status"] = "Completed";
                    //SPRoleAssignmentCollection SPRoleAssColn = wfitem.RoleAssignments;
                    //for (int i = SPRoleAssColn.Count - 1; i >= 0; i--)
                    //{
                    //    SPRoleAssignment roleAssign = SPRoleAssColn[i];
                    //    SPRoleAssColn.Remove(i);
                    //}
                    //wfitem.Update();

                    updatelist("Remainder3", false);

                    SPListItem wfitem = workflowProperties.Item;
                    wfitem["Status"] = "Completed";
                    wfitem.SystemUpdate();
                }
            }
            catch (Exception ex)
            {
               // datechk = false;
                SendEmailToAdmin(ex.Message);

            }

        }
        private void updatelist(string field, Boolean value)
        {
            SPListItem wfitem = workflowProperties.Item;
            wfitem[field] = value;
            wfitem.SystemUpdate();
        }

I tried with Designer Reusable workflow . Attached is my Designer Workflow. As stated below we can not get the Updated Status Column when we go for Reusable workflows. When I used Title the workflow is working fine

Designer Workflow

  • Does any expertise have a solution for the above . Please help me o this .... – santosh kondapalli May 13 '14 at 2:53
  • I have Tried the above code but the problem is when the item is Edited by the user through the List. The workflow is going to the Error State.(Geeting the save conflicts error). Can any one throw some light on this please – santosh kondapalli May 19 '14 at 16:03
  • is there any specific reason you have option to create VS workflows instead of using sharepoint designer workflow.Looks like this can be done using designer workflows as well – Unnie May 20 '14 at 13:33
  • I want to use this Workflow as Reusable. When I tried with designer workflow when it is assigned to a content type on the Task list I can't update the status column. The only fields I can update is Title, Name . I think this is a limitation in Designer Reusable workflows – santosh kondapalli May 20 '14 at 16:17
  • I also attached the designer workflow scenario here . – santosh kondapalli May 20 '14 at 16:36
0

If a understand you query, You can probably use some custom timer job which will iterate through all the open tasks and based on your custom logic it will send emails to the specific users. You can send email by SPUtlity.Send email and you can even end the workflow programatically from this/

This is only a another solution to your problem.

  • Thanks for your suggestion. But I want to use this as reusable in 100 sub sites. So timer job wont work in this scenario. – santosh kondapalli May 20 '14 at 16:18
  • I don't understand your point. Why timer job wont work in this scenario. You can create timer job at web application level and it can work for as many sites as you want. Correct me if i am wrong anywhere. – Aanchal May 20 '14 at 17:00
  • Eventhough timmer job activated at web application level. Once you activate on one site and try to activate on another site it gets activated but it will not work on the first site.it overwrites it. – santosh kondapalli May 22 '14 at 8:28
  • There will be only one web application feature for activating timer job. There is no need to activate on each and every site. – Aanchal May 22 '14 at 8:34
0

I know it's not VS solution, but for exactly that kind of scenarios I use HarePoint Workflow Scheduler.
It's free for commercial use and extremely easy to use as well.

What you need to do is to create a simple workflow in SharePoint Designer that checks if Today is the day you require (for example DueDate-2).
If yes, do whatever needs to be done, if not then stop the workflow.
And schedule this workflow in HarePoint to be run once a day at 1am (for example).

  • Thanks, but it is too much complicated right when we use it in 100 sub sites and refreshing this column.....aND WHAT ABOUT ALREADY RUNNING INSTANCES during this time?? – santosh kondapalli May 22 '14 at 8:30
0

I was able to achieve this by creating a calculated column which has the status modified. During this time I am delaying the workflow for 2 days in the workflow.

At this time I am checking this calculated column with current item. If status is completed I am ending the workflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.