locked
Sharepoint custom workflow assign a task to a group programatically RRS feed

  • Question

  • I am new to WF. I have not got a clue!!!..How can I do it please?
    rsoares
    Monday, May 11, 2009 6:25 PM

Answers

  • Drag the Create Task Activity on to your Workflow design.

    Bind the required parameters like Corelation token, taskproperties..

    Right click on the activity and select "Generate Handlers", which takes you to the code view,,

    Use this code below under thr respective task method handler generated

    // Create unique Task Id.
        taskId = Guid.NewGuid();

        // Set task properties.
        taskProperties.TaskType = 1;   
        taskProperties.Title = "Approval";
        taskProperties.StartDate = DateTime.Today;
        taskProperties.PercentComplete = 0.0f;
        taskProperties.AssignedTo = Domain + "\\" + SecurityGroupName;

    Follow this link for better understanding on how to design n code workflows in sharepoint - http://msdn.microsoft.com/en-us/library/cc627283.aspx Also use the examples in the sharepoint SDK

    Wednesday, May 13, 2009 12:37 PM
  • Hi,
    If you are using Visual Studio to developing workflow, just need to set the AssignedTo property of SPWorkflowTaskProperties to the group login name.
    My blog: http://xiaoshatian.cnblogs.com
    Tuesday, May 12, 2009 1:06 AM
  • Cautionary, If your task list you have associated the workflow to is using the base column "Assigned to" with an Allow multiple selections: setting of YES.
    Then workflows (Sharepoint Designer or Visual Studio) will Error (specifically on an end task activity).
    Wednesday, May 13, 2009 4:55 PM
  • Hi,

    Instead of restarting the workflow, you can just use a state machine workflow and go to the begining state or any other state you want to go to when a rejection is made.

    To get some code samples, just have a look at the SDK. There are good samples on workflows, state machines & sequential.

    Best Regards
    Wednesday, May 13, 2009 7:24 PM


  • Below code snippet implies that peope  have approved /  rejects the document it shud reside inside the workflow.cs file which is a staemachine WF 


    public sealed partial class Workflow1 : StateMachineWorkflowActivity

    {

    public Workflow1()

    {

    InitializeComponent();

    }

     

    public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

    public SPWorkflowTaskProperties createTaskWithContentType1_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

     

    public SPWorkflowTaskProperties onTaskChanged1_AfterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

    public SPWorkflowTaskProperties onTaskChanged2_AfterProperties2 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

     

    private void createTaskWithContentType1_MethodInvoking(object sender, EventArgs e)

    {

    try

    {

     

    SPGroup oGroup = workflowProperties.Web.Groups["approvergrp"];

    SPFieldUserValue oFieldUserValue = new SPFieldUserValue(oGroup.ParentWeb, oGroup.ID, oGroup.Name);

    SPWeb ospweb = workflowProperties.Web;

    //strURL = workflowProperties.WebUrl + "/Lists/Tasks/AllItems.aspx";

    SPList osplist = ospweb.Lists["spList"];

    SPListItemCollection oSPListItemColl = osplist.Items;

    SPListItem oSPListItem = workflowProperties.Item;

     

    this.createTaskWithContentType1_TaskId1 = Guid.NewGuid();

    this.createTaskWithContentType1_TaskProperties1.Title = "Please Approve / Reject  Details Provided By Requestor.";

    this.createTaskWithContentType1_TaskProperties1.AssignedTo = oFieldUserValue.LookupValue;

    this.createTaskWithContentType1_TaskProperties1.Description = "Please Approve / Reject the Details Provided By Requestor.";

    }

    catch() {}

    }

    SPListItem oSPListItem = workflowProperties.Item;

    private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
    {

    if (onTaskChanged1_AfterProperties1.ExtendedProperties["TaskStatus"].ToString() == "Approve")

    {

    ifVarapproverApproved = true;

    strTaskDescription = "Workflow has been approved by approver";

    strTaskOutcome = "Workflow sent to next level";

    }

    if (onTaskChanged1_AfterProperties1.ExtendedProperties["TaskStatus"].ToString() == "Reject")

    {

    ifVarapprverRejected = true;

    strTaskDescription = "Workflow has been rejected by aprover";

    strTaskOutcome = "Workflow Completed";

    oSPListItem["Form_Status"] = "REJECTED";

    }

    oSPListItem.Update();

    }

    HTH

    prasadwt

    Friday, May 15, 2009 8:28 AM

All replies

  • Hi,
    If you are using Visual Studio to developing workflow, just need to set the AssignedTo property of SPWorkflowTaskProperties to the group login name.
    My blog: http://xiaoshatian.cnblogs.com
    Tuesday, May 12, 2009 1:06 AM
  • Could you kindly show me a piece of CODE


    Many thanks

    Regards

    Rodolfo
    rsoares
    Tuesday, May 12, 2009 2:47 PM
  • Drag the Create Task Activity on to your Workflow design.

    Bind the required parameters like Corelation token, taskproperties..

    Right click on the activity and select "Generate Handlers", which takes you to the code view,,

    Use this code below under thr respective task method handler generated

    // Create unique Task Id.
        taskId = Guid.NewGuid();

        // Set task properties.
        taskProperties.TaskType = 1;   
        taskProperties.Title = "Approval";
        taskProperties.StartDate = DateTime.Today;
        taskProperties.PercentComplete = 0.0f;
        taskProperties.AssignedTo = Domain + "\\" + SecurityGroupName;

    Follow this link for better understanding on how to design n code workflows in sharepoint - http://msdn.microsoft.com/en-us/library/cc627283.aspx Also use the examples in the sharepoint SDK

    Wednesday, May 13, 2009 12:37 PM
  • Cautionary, If your task list you have associated the workflow to is using the base column "Assigned to" with an Allow multiple selections: setting of YES.
    Then workflows (Sharepoint Designer or Visual Studio) will Error (specifically on an end task activity).
    Wednesday, May 13, 2009 4:55 PM
  • Thanks Mahesh and Toomanyhats

    I have this scenario I need to create a task and assign it to a group so far I got it. But what activity or activities can I use to check with everybody in the group have approved or rejected it. If someone has rejected I have to restart the workflow. Please kindly show me some code.

    Many thanks

    Rodolfo
    rsoares
    Wednesday, May 13, 2009 7:15 PM
  • Hi,

    Instead of restarting the workflow, you can just use a state machine workflow and go to the begining state or any other state you want to go to when a rejection is made.

    To get some code samples, just have a look at the SDK. There are good samples on workflows, state machines & sequential.

    Best Regards
    Wednesday, May 13, 2009 7:24 PM
  • thanks stephen

    I was thinking of a state machine workflow. But how can I check people that have approved or rejected a document. I need to loop the group that I will assign the task for it. Is there an example on the SDK. I am downloading it right now:)

    Regards

    Rodolfo
    rsoares
    Wednesday, May 13, 2009 7:35 PM


  • Below code snippet implies that peope  have approved /  rejects the document it shud reside inside the workflow.cs file which is a staemachine WF 


    public sealed partial class Workflow1 : StateMachineWorkflowActivity

    {

    public Workflow1()

    {

    InitializeComponent();

    }

     

    public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

    public SPWorkflowTaskProperties createTaskWithContentType1_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

     

    public SPWorkflowTaskProperties onTaskChanged1_AfterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

    public SPWorkflowTaskProperties onTaskChanged2_AfterProperties2 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

     

    private void createTaskWithContentType1_MethodInvoking(object sender, EventArgs e)

    {

    try

    {

     

    SPGroup oGroup = workflowProperties.Web.Groups["approvergrp"];

    SPFieldUserValue oFieldUserValue = new SPFieldUserValue(oGroup.ParentWeb, oGroup.ID, oGroup.Name);

    SPWeb ospweb = workflowProperties.Web;

    //strURL = workflowProperties.WebUrl + "/Lists/Tasks/AllItems.aspx";

    SPList osplist = ospweb.Lists["spList"];

    SPListItemCollection oSPListItemColl = osplist.Items;

    SPListItem oSPListItem = workflowProperties.Item;

     

    this.createTaskWithContentType1_TaskId1 = Guid.NewGuid();

    this.createTaskWithContentType1_TaskProperties1.Title = "Please Approve / Reject  Details Provided By Requestor.";

    this.createTaskWithContentType1_TaskProperties1.AssignedTo = oFieldUserValue.LookupValue;

    this.createTaskWithContentType1_TaskProperties1.Description = "Please Approve / Reject the Details Provided By Requestor.";

    }

    catch() {}

    }

    SPListItem oSPListItem = workflowProperties.Item;

    private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
    {

    if (onTaskChanged1_AfterProperties1.ExtendedProperties["TaskStatus"].ToString() == "Approve")

    {

    ifVarapproverApproved = true;

    strTaskDescription = "Workflow has been approved by approver";

    strTaskOutcome = "Workflow sent to next level";

    }

    if (onTaskChanged1_AfterProperties1.ExtendedProperties["TaskStatus"].ToString() == "Reject")

    {

    ifVarapprverRejected = true;

    strTaskDescription = "Workflow has been rejected by aprover";

    strTaskOutcome = "Workflow Completed";

    oSPListItem["Form_Status"] = "REJECTED";

    }

    oSPListItem.Update();

    }

    HTH

    prasadwt

    Friday, May 15, 2009 8:28 AM
  • Hi Prasad

    The code looks as if it will work. I will have a go and let you know. Many thanks so far

    Regards

    Rodolfo

    rsoares
    Tuesday, May 19, 2009 6:55 PM