Tuesday, June 25, 2013

In my previous posts, I mentioned many times the benefits of using Demand Management workflow for Project Server from Solution Starters project (I described it in this post).I am very satisfied with its possibilities, but one flaw was really bothering me. Problem is, you can not fetch the username of approver of a stage in workflow. You can get to any sort of workflow data, but this approver information seems to be hidden. But, after hours of searching,I managed to find it. I must say, that, this isn't the nicest solution, but I think it is the only one and this works 100 %. If you know any other way, please, let me know.Approver's username is hidden in OfficeTask, in ConsolidatedComments. But, it is mixed with bunch of other stings, so, I extracted with this method:

I know that this looks pretty odd, but, it works. I'll try to explain what I am doing here. Let's say that we have a task that needs to be approved (or rejected) by 3 different approvers. First user (let's say his name is Rajesh Koothrappali :) ) approves task. Now, ConsolidatedComments field looks something like this:

"Approved by Rajesh Koothrappali
on 05/05/2013"

These methods will extract Rajesh Koothrappali from this string.

Now, second user (let's say his name is Howard Wolowitz) approves the task. Now, ConsolidatedComments field looks something like this (it is appended to the last string):

"Approved by Rajesh Koothrappali
on 05/05/2013;Approved by Howard Wolowitz
on 05/05/2013"

Our methods will now extractHoward Wolowitzfrom this string.

Finally, third user, Sheldon Cooper comes and he rejects the task. Now, ConsolidatedComments field looks something like this (it is appended to the last string):

"Approved by Rajesh Koothrappali
on 05/05/2013;Approved by Howard Wolowitz
on 06/05/2013;Approved by Sheldon Cooper
on 07/05/2013;"

Our methods will now returnSheldon Cooperas approver.

As you can see, we are always fetching the last username in that string. Hope you will find it helpful.