0

I've got a state-machine workflow with custom instantiation and task asp.net forms.
My custom task form is pretty easy, it just shows the instantiation data and let the user approve or reject it. If he reject it, he has to write a reason into a TextBox.

But now I don't know how I can pass the value of the TextBox back to the Workflow. I know that there are AfterProperties and I do link them to the onWorkflowChanged event but I don't know how I can insert a value from an asp.net form into them.

So my question is how can I pass an user input from an asp.net form back to the workflow? I can only use Visual Studio 2010 and C# to solve my problem.

1 Answer 1

0

I figured it out by myself.
I've added the code below to the OnClick event of my reject-button.

protected void Button_Reject_Click(object sender, EventArgs e)
{
    try
    {
        SPListItem spListItem = SPContext.Current.ListItem;

        Hashtable ht = new Hashtable();
        ht[SPBuiltInFieldId.PercentComplete] = 1.0f;
        ht[SPBuiltInFieldId.TaskStatus] = "@"; // @ to reject the task
        ht["Reason"] = this.tbxReason.Text; // Add the TextBox value to the Hashtable
        SPWorkflowTask.AlterTask(spListItem, ht, true); // Alter the task...

        CloseForm();
    }
    catch
    {
        // Nothing
    }
}

In the CompleteTask event of the workflow I can now easily access the value of the Textbox in the TaskAfterProperties.

private void ApproveCompleteTask_MethodInvoking(object sender, EventArgs e)
{
    Debug.WriteLine("ApproveCompleteTask] started");

    // Get the TaskAfterProperties
    Hashtable properties = this.TaskAfterProperties.ExtendedProperties; 
    // Get the value from the Hashtable
    String reason = Convert.ToString(properties["Reason"]);

    // Do whatever you want to do with it

    Debug.WriteLine("ApproveCompleteTask] completed");
}

I hope it helps someone else, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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