Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created an custom workflow activity specified here: SPWeb.GetListItem returns null in custom workflow activity

Now I need to know the user who last updated the associated workflow task.

Before my workflow activity is executed, the workflow would "Collect data from a user". When that user provides requested data, the workflow proceeds to execute my custom activity.

Now, I know this can be defined as a property of the activity, but I need to retrieve this automatically (if possible). So far, this is what I have:

var taskList = __Context.Web.Lists[new Guid(__Context.TaskListGuid)];

And I was thinking of getting the "last" associated task with something like this:

// get a reference to the task list
var taskList = __Context.Web.Lists[new Guid(__Context.TaskListGuid)];
// find all tasks which were created by this workflow instance
var items = taskList.Items.Where(i => i.AssociatedItemId == __Context.ItemId).OrderByDescending(i => i.LastUpdated);
// get the task that was updated most recently
var lastItem = items.FirstOrDefault();
// get the user who updated that task
var user = lastItem.UpdatedBy

Obviously, this is not the actual code, but an idea I have in my mind. Is this the right way to do this? if so, how can I go about it (actual code)?

share|improve this question
    
Try to use CAML Query for getting tasks, also it is more correctly with performance point. example of query: <Query> <Where> <Eq> <FieldRef Name="ID" /> <Value Type="Integer">1</Value> </Eq> </Where> <OrderBy> <FieldRef Name="Modified" Ascending='FALSE' /> </OrderBy> </Query> –  Roman Apr 12 at 9:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.