获得批准状态

时间:2012-07-10 12:43:04

标签: c# sharepoint sharepoint-2010 workflow sharepoint-workflow

我在visualstudio 2010中为sharepoint 2010创建了一个批准工作流程。 工作流在开始时创建任务,然后等待批准任务。但是如何检查任务是否被批准?

Perhabs我更详细地描述了我的szebario:

  • 我有一个项目列表,必须在添加后进行审核。
  • 如果他们获得批准或拒绝,那将是绝对的决定,永远不应该改变
  • 如果该项目获得批准,某些功能将被解雇
  • 如果被拒绝,则应发送邮件!

我的想法:

创意 - 工作流程

我的第一个想法是创建一个在添加ListItemd后被触发的工作流。 WF应该创建一个可以审查的任务。如果它是肯定的,它应该激活一些函数并自行删除它。

Idea-工作流程设计: enter image description here

Idea-工作流程代码:

       public Guid workflowId = default(System.Guid);
            public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
            // these properties are for the workflow task that will be created.
            public SPWorkflowTaskProperties CreateTaskApproval_TaskProperties = new SPWorkflowTaskProperties();
            public SPWorkflowTaskProperties CreateTaskApproval_AffterTaskProperties = new SPWorkflowTaskProperties();
            public SPWorkflowTaskProperties CreateTaskApproval_BeforeTaskProperties = new SPWorkflowTaskProperties();
            public String CreateTaskApproval_ContentTypeId = default(System.String);
            public Int32 CreateTaskApproval_ListItemId = default(System.Int32);
            public Guid CreateTaskApproval_TaskId = default(System.Guid);

       private void createTask1_MethodInvoking(object sender, EventArgs e)
            {
                createTask1.TaskId = new Guid();
                // Now create the approval task.
                // Set up some of the properties.
                CreateTaskApproval_TaskId = Guid.NewGuid();
                //Setting the task properties
                CreateTaskApproval_TaskProperties.Title = "TestTitle"
                CreateTaskApproval_TaskProperties.Description = "Description";
                CreateTaskApproval_TaskProperties.AssignedTo = @"testemail\testuser";
                CreateTaskApproval_TaskProperties.SendEmailNotification = false;
                CreateTaskApproval_TaskProperties.TaskType = 1;
                LogComment("Request Task Created.");
            }
         private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
            {
                try
                {
//!!!! The Problem is here at Status
                    // Check to make sure the field is there on the item.
                    if (CreateTaskApproval_TaskProperties.ExtendedProperties["Status"] != null)
                    {
                        // Evaluate the value of the field.
                        if (CreateTaskApproval_TaskProperties.ExtendedProperties["Status"].ToString() == "Approved" || CreateTaskApproval_TaskProperties.ExtendedProperties["Status"].ToString() == "Declined")
                        {

                            TaskApproval_ApproveComplete = true;

                        }
                        else
                        {
                            TaskApproval_ApproveComplete = false;
                        }
                    }
                    else
                    {
                        // This should never happen because there is a default, but always good just in case.
                        TaskApproval_ApproveComplete = false;
                    }
                }
                catch (Exception ex)
                {
                    TaskApproval_ApproveComplete = false;

                    LogComment(ex.ToString());
                }
            }
            private void completeTask1_MethodInvoking(object sender, EventArgs e)
            {
                workflowProperties.Item.ModerationInformation.Status = SPModerationStatusType.Approved;
    //Fire some code

            }

理念 - 工作流程 - 问题: 我根本无法获得任务审核状态。 (“已批准”等)

CreateTaskApproval_TaskProperties.ExtendedProperties["Status"]

有没有人知道怎么办?

1 个答案:

答案 0 :(得分:1)

您可以在更改后获取任务状态 - 从任务的AfterProperties(在设计器中创建)。然后,您必须使用onTaskChanged1的处理程序“Invoked”来获取AfterProperties对象并获取ExtendedProperties [“isApproved”]以查看任务批准。

示例方法:

    private void Invoke_Task1_TaskChanged(object sender, ExternalDataEventArgs e)
    {
        Task1_IsCompleted = bool.Parse(task1_AfterProperties.ExtendedProperties["isFinished"].ToString());
        Task1_IsApproved = bool.Parse(task1_AfterProperties.ExtendedProperties["isApproved"].ToString());

        if (Task1_IsCompleted)
        {
            ManagerReason = task1_AfterProperties.ExtendedProperties["ManagerReason"].ToString();
        }
    }

希望它有所帮助。