开发者

how can i get all users who have interacted with a sharepoint workflow

开发者 https://www.devze.com 2023-04-03 05:02 出处:网络
I have a custom state machine workflow written in VS2010, when the workflow is canceled, or completed, I need to send an email to all the users who have interacted(completed/changed a task or the docu

I have a custom state machine workflow written in VS2010, when the workflow is canceled, or completed, I need to send an email to all the users who have interacted(completed/changed a task or the document) with the given workflow. I have been unable to figure 开发者_如何转开发out a good way to get the list of users whom I need to send my email to. Any suggestions?


A simple way would be to obtain the collection of the tasks assigned during the workflow process by checking the item's workflow tasks and finding out who they were assigned to. Loop through these tasks and build a List of the user to whom each was assigned.

Then, check the versions of the item to see who created each version, and add this user to the aforementioned List:

    /// <summary>
    /// This helper method will return a List of strings representing users who modified an item
    /// or were assigned a workflow task for the item.
    /// </summary>
    /// <param name="item"></param>
    /// <returns></returns>
    private List<string> GetUsersForWorkflow(SPListItem item)
    {


        List<string> assignees = new List<string>();

        //Get task editors
        Microsoft.SharePoint.Workflow.SPWorkflowTaskCollection tasks = item.Workflows[0].Tasks; //Get the workflow by GUID alternatively 
        foreach (Microsoft.SharePoint.Workflow.SPWorkflowTask task in tasks)
        {
            string assignee = task["Assigned To"].ToString();
            assignees.Add(assignee);
        }

        //Get version creators
        SPListItemVersionCollection versions = item.Versions;
        foreach (SPListItemVersion version in versions)
        {
            string assignee = version.CreatedBy.ToString();
            assignees.Add(assignee);
        }

        return assignees;
    }

You can then play with the tasks if you want to email only those who have completed tasks, etc. You can get the workflow author (item.Workflows[0].Author) and email him/her, as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消