With Project Server 2010 you get an out of the box workflow named ‘Sample Proposal Workflow’, this is quite a good demonstration as it includes all of the usual things you might see in such a process; Validation, Approval, Selection, etc. However unfortunately as of this time (days before RTM) the source for this sample is still not available, at the moment the only SDK example is a simple Branching Workflow which only includes a single validation step.
I had an opportunity at the Sydney Ignite to ask Jan Kalis about this one, and he assured me that the full source for the sample will be released sometime around RTM, but we’ll have to wait a little bit more for that one.
In the meantime the world moves on and I have been busily writing my first full blow demand management workflow for a customer deployment, and so I thought I would share some of what I have done here. To that end I have taken the SDK Branching Workflow and extended it to include an Approval stage similar to that in the Sample Proposal Workflow.
Read below for what I have done and what you need to test it for yourself, then download my Visual Studio 2010 project below.
Branching Workflow with Approval:
The steps below are a summary of the changes made to the Branching Workflow, for a more complete how-to guide I very strongly suggest that you read the SDK Branching Workflow article and if you complete the examples there you will end where my steps below begin. Furthermore all the general requirements for getting this running (Visual Studio 2010 etc) are in the SDK article.
Before you start (or download):
This example is built on a default PWA instance, I have renamed the out of the box Sample Proposal Workflow to ‘Branching Workflow with Approvals’ then after deploying the code changed the workflow selected to the new one. All other PDPs and Stages are used as is, and the only other change required is an optional one below in step 5 below (see image).
Changes Made:
- Starting with the SDK Branching Workflow (note that if you download it in the p14betasdk then the code is incomplete and a few steps from the MSDN article must be completed). I also renamed the Feature and the Workflow in the deployment package to avoid confusion.
- Then I added a pre-build event command to automatically regenerate the Strong Name. (Can be removed, but just makes testing easier)
- Added a step after the Proposal Details Stage where the workflow goes to Proposal Selection Stage in Select Phase (updateProjectStageStatus20 – Waiting for Approval) – Note I have used the Select phase as my ‘Approval’ phase, I am not doing anything with Portfolio Selection here just approval.
- Next I read the Project Properties of "Project Name" and "Owner" for the Workflow Task (These are optional and just for completeness).
- Read "Portfolio Managers" Project Server Group membership to create approval request for first person returned in group.
- Create Workflow Task using CreateTaskWithContentType and assign to approver and populate task properties with Project Name and Owner.
Important: In order for these task properties to work you must ad the built in Columns to the PSWApprovalTask content type by editing the Default Workflow Approvals, then updating the content type to include the existing list columns.
(See Screenshot from List Settings PSWApprovalTask Content Type Properties)
- Then we add a while activity onTaskChanged to wait for the Approval task to be actioned. In this step the ExtendedProperties are checked for a value "Approved" anything else results in Rejection.
- And finally an IfElseActivity is used to branch on the Approved / Rejected result.
- If true then continue to end and UpdateProjectStageStatus to Execution stage.
- Else UpdateProjectStageStatus to Not Selected state and Terminate.
Here is the result in Visual Studio:
What’s left?
- Email notification? You can simply use the SharePoint list notifications on the Workflow Task list as a simple and consistent email notification method.
- Portfolio Selection? I’ll leave that one to you.
Technical Details:
This example was created on the following beta software, meaning that things might change by RTM:
- SharePoint Server 2010 RC Build
- Project Server 2010 RC Build
- Visual Studio 2010 RC Build
Download the full project files in a zip here. (*see update below)
MSDN References:
How to: Create a Branching Workflow <http://msdn.microsoft.com/en-us/library/ee767701(v=office.14).aspx>
Step 3: Create the Workflow <http://msdn.microsoft.com/en-us/library/ms580283.aspx>
UPDATE 3/09/2010:
I thought that I’d revisit this one as clearly from the comments there was something wrong after RTM, basically the problem everyone seems to be having relates to the ‘WorkflowTaskCTypeID’ defined. Somehow what I had in the BranchingWorkflow.cs file is actually incorrect, the solution has the following on line 46:
public String WorkflowTaskCTypeID = “0x0108010038A52C27344148C9B9214F82C7C0298500544602C73FFD1245BCC090442C85426B”;
When it should be:
public String WorkflowTaskCTypeID = “0x0108010038A52C27344148C9B9214F82C7C02985?;
Not quite sure where the first one came from (and why it worked?!) but that fixed it for me. If you update that line then recompile / rebuild you should be good.
PS. I don’t use the CreateTaskWithContentType anymore, have a look at the 2010 workflow activity (OfficeTask class) used in the Sample Proposal found in the SDK: http://msdn.microsoft.com/en-us/library/microsoft.office.workflow.actions.officetask.aspx
Hai Martin..
you done great job. Am appreciating you very much..
Its working fine for me.
Another task is how to do portfolio selection..
Thanks in advance
iqbalkmk
Hai..Martin
I need help regarding portfolio select and resource plan. This is urgent for me. Can u describe me how to do this job.
I need full result, I am new in sharepoint. I started from 2010 onwards only..
Thank you in advance..
iqbalkmk
Hi Iqbal,
I have not looked into the Portfolio Selection part of the workflow as I have yet to have a requirement for that functionality, however my expectation is that the ‘selected’ status would be represented by a custom field which you would then just have to enumerate and compare in the workflow, in the same fashion as the initial cost comparison.
Otherwise according to MS the full source for the Sample Proposal will soon be released (around the time of RTM this month) so from there you will get a full solution.
Hope that helps,
Martin
Hai Martin
I tried to find Selected filed.
But there is no such custom field in PWA.
I need to go 2 steps thats resource planing and Execute.
I didnt find “%complete” field in pwa also.
I m really struggling.
.
Thanks in advance
iqbalkmk
Hi Iqbal,
You’re correct there is no custom field I was mistaken there, however I found this while working on another issue yesterday; OnProjectCommit see on MSDN: http://msdn.microsoft.com/en-us/library/microsoft.office.project.server.workflow.onprojectcommit(office.14).aspx
That looks quite like the Commit to Portfolio that you are after..
Oh and % Complete can be found by using ReadProjectProperty or CompareProjectProperty..
Hope that helps,
Hai Martin
Now am in final stage. I want to finish my workflow today itself. But i didnt find the solution.
As u said i tried but its not working.
In Execution phase, Schedule stage must be wait for until set %complete field 100%.
Schedule PDP contains the task name,start,finish,%complete field etc, This is the field am looking and want to compare.
Please help me as soon as possible..
Thank you in advance
iqbalkmk
Hai Martin
Sorry i want two things to finish Resource planing and Execution .
As u said i tried but its not working.
In Execution phase, Schedule stage must be wait for until set %complete field 100%.
Schedule PDP contains the task name,start,finish,%complete field etc, This is the field am looking and want to compare.
Please help me as soon as possible..
Thank you in advance
iqbalkmk
Hai Martin
Sorry i want two things to finish Resource planing and Execution .
As u said i tried but its not working.
In Execution phase, Schedule stage must be wait for until set %complete field 100%.
Schedule PDP contains the task name,start,finish,%complete field etc, This is the field am looking and want to compare.
Please help me as soon as possible..
Thank you in advance
iqbalkmk
Hai Martin…
Am getting one more scenario to develop project server workflow.
I need to go to previous stage if the approver rejects or resubmit the project and resubmit again from previous stage. (I mean dont want terminate the workflow in a particular stages)
How to implement this steps…
Thanks in advance
iqbalkmk
Hi Iqbal,
I had a similar requirement in my workflow, what I ended up doing was to just enclose the entire approval stage in a While loop, if approval was not given then the while loop would return to the previous setProjectStage, etc.
HTH.
hai martin …
I also did like that but it gives error…
Assertion Break Error..
got an error in the workflow when am hitting submit button again.. “Assertion Failed”
myObject.CallbackCompleted(PDPCommandQueue.Queue, “NextStepCheck” , “hAn error has occurred in the workflow.Contact your system administrator.”, null);
defd = typeof(SP.UI.SocialData.TRCRibbonComponent);
I only add approval stage in a while loop..
thanks in advance..
Hai Martin…
Can u Please upload that extended source code here….
I didnt find what mistaken i have done…
or mail me [email protected]
Thanks in advance..
Hai Martin…
I am really struggling with this error . I didnt find any solution yet. I added the approval stage in a while loop. Its working fine. The error is occur when am clicking submit button after rejects..
Please help me as soon as possible….
Thanks in advance
iqbalkmk
Hi Iqbal,
Not sure what more I can offer on this one other than have you had a look at the “Sample Proposal2” MSDN code with the now released SDK? That covers most scenarios including a While loop (on portfolio selection).
Find it here on MSDN: http://msdn.microsoft.com/en-us/library/ms512767.aspx
Hi Martin
My workflow gets errors when implementing the CreateTaskWithContentType. Does the string WorkflowTaskCTypeID have to beset to something PWA specific?
I’m also not sure where to add the columns in the PSWApprovalTask contenttype – where is this done?
Hope you can help me make this approval part work.
I thing that might be interesting and important – I’m running a PWA in danish. This includes national status codes and field names. I suspect this is vital!?
Yes the WorkflowTaskCTypeID needs to point to the SharePoint ID of the content type used, in a default PWA instance that ID is (from the code example in this blog):
public String WorkflowTaskCTypeID = “0x0108010038A52C27344148C9B9214F82C7C0298500544602C73FFD1245BCC090442C85426B”;
My guess would be that would be the same regardless of language, however that’s not guaranteed.
You can check this by looking at the “Workflow Approvals” list settings in the “PSWApprovalTask” content type, the URL gives you the “ctype=” ID number.
In the same place you can change the columns available in the list by using the “Add from existing site columns” to add those from the PSWApprovaltask.
HTH,
Thanks. I’ve updated the ctyeID and added the columns. I still get an “Unknown error” though…
Addition: I can debug my way all through the code in “createTask_Approval” but after that the error comes. The Task object has all the properties set when the functions ends.
If I remove the createTaskWithContentType1 (I havent added the WhileActivity yet) the workflow works fine.
I can manually add items in the task list so its not a security problem (as far as I can tell).
Hi again
I started all over with your project, changed the GIUD’s to reflect my system and try to deploy. I get this error:
Error occurred in deployment step ‘Activate Features’: Failed to create workflow association ‘BranchingWorkflowApproval’. Cannot find SharePoint list with name “Project Server Workflow Tasks” or GUID “2ee713cf-c6d4-4971-bf2f-c7ac2ce0e0bb”.
I can see that the list has another GIUD than in the error message!
Is there a place in the project I have to identify the Project Server Workflow Tasks list?
OK – I found the place where to locate the task list and was able to deplay the workflow.
I get the same error though when the workflow has to create an approval task :-(
The IfElse activity to test the cost works fine.
Can it be related to some security settings?
Ah okay so the GUID’s must all be different in different languages, that’s annoying!
Also remember that the code above was written for the RC version of 2010 so there may be other changes, I would suggest that you re-setup the toolbox Workflow Components by following the steps in this MSDN article: http://msdn.microsoft.com/en-us/library/ee767686.aspx then attempt to recreate the CreateTaskWithContentType activity as I cannot see any other reason other than some compile time problem that could cause this.
HTH,
Hi Martin,
This worklfow is not working in RTM…
Do we need to change anything…
Thanks in advance
iqbalkmk
Hi,
I’d suggest checking all the GUID’s and recompiling with both RTM versions of SharePoint, Project and Visual Studio installed. Otherwise there is nothing in there that wouldn’t work on RTM.
HTH,
I also same error:
WHAT’S WRONG ?
I also did like that but it gives error…
Assertion Break Error..
got an error in the workflow when am hitting submit button again.. “Assertion Failed”
myObject.CallbackCompleted(PDPCommandQueue.Queue, “NextStepCheck” , “hAn error has occurred in the workflow.Contact your system administrator.”, null);
defd = typeof(SP.UI.SocialData.TRCRibbonComponent);
I only add approval stage in a while loop..
thanks in advance..
I thought that I’d revisit this one as clearly there was something wrong, basically the problem everyone seems to be having relates to the ‘WorkflowTaskCTypeID’ defined. Somehow what I had in the BranchingWorkflow.cs file is actually incorrect, the solution has the following on line 46:
public String WorkflowTaskCTypeID = “0x0108010038A52C27344148C9B9214F82C7C0298500544602C73FFD1245BCC090442C85426B”;
When it should be:
public String WorkflowTaskCTypeID = “0x0108010038A52C27344148C9B9214F82C7C02985”;
Not quite sure where the first one came from (and why it worked?!) but that fixed it for me. If you update that line then recompile / rebuild you should be good.
Thank you Martin. It worked for me. I found this solution yesterday. :)
But I had a new problem. I suppose I use office task instead of createtask activities. If you create a new excample that about it, we all to be pleased that.
Thank you again.
Firat,
Hi martin,
Thank you for advising me.
I have another scenario for me.
I need to add more approval options in pwsapproval task form like Approve/Reject/Rework to initiator etc..
How can i create new approval task content type using ribbon?
I tried to create content type but i dont know how to add ribbons in edit form and integrate in workflow.
I think some others have same scenario..
Can you help me?
Thanks in advance
iqbalkmk
Hi Martin,
I am a newbie in Project Server Custom Workflow Development. I am buidling a custom State Machine Workflow to implemented on Workflow Stages that I have defined myself in Project Server 2010. The forms have been built in infopath forms/sharepoint list.
Please see the following scenario:
User sets the status to “Concept Development”. I want the workflow to move when the user sets the status, “Concept Submitted”, otherwise it should keep waiting and do nothing.
I am using CompareProjectProperty to compare if the status has been set to “Concept Submitted”. I want the workflow to wait until user changes the status to “Concept Submitted”. In CompareProjectProperty methods/fields, if I set “WaitUntilValueIsSet = True”, will it work i.e. will it wait until the status is set to “Concept Submitted” and then move along? How long will it wait?
Please help me with this problem.
Thanks in advance,
Amna.
Hi Amna,
It sounds to me like you simply need a While loop around your CompareProjectProperty, that way it will wait forever until that property matches the required value!
Martin
Hi Martin,
I have a question that is related to another question that was asked previously, but haven’t seen a response for that.
The default task approval form only has the approve/reject buttons. I need to be able to customize the options available, and also, be able to capture different fields of information other than the “Comments” field of data. In SharePoint I would create a different content type with custom forms. Is this possible to do in Project Server 2010? Could I have different buttons show up and have different actions occur based on the buttons?
Thanks.
Hi Michael,
Yes you hit the solution exactly with your suggestion, the approval form is simply a custom Sharepoint content type, if you replace it with your own custom content type and update the workflow task activity to use that content type then you will be able to add whatever customizations that you need.
It’s not something I’ve yet had the need to do, so I can’t say much more than that unfortunately..
HTH,
Hello Martin,
I have a tiny problem to which I cannot find solution.
I created simple project 2010 workflow which has only two stages in is linear – it is very simple. I have successfully deployed it on the server and created Enterprise Project Type with that workflow. Then I try to test that workflow and is initializing a long time. It gives me dialog window to check queue jobs (all are marked as successful) but when I try to open that project it gives me:
‘Unable to open the project. The project has not been properly initialized. This may be caused by the workflow associated with the Enterprise Project Type not starting correctly. Please contact your system administrator’
The only thing I found that there are maybe wrong stage ids set or any other properties. But I triple checked everything. What can I do? Do you have any advice how can I troubleshoot this issue?
Thanks in advance
Hi,
Best bet is to check the ULS logs, you will see the reason for the failure there probably in an exception caused by the code. Additionally the Workflow History sharepoint list shows a little information which may be enough for you to find the cause of this problem.
Martin
Hi Tomaz,
I am facing exactly the same issue. did you happen to fix the issue. If so could you please share.
Thanks
Sreeni
Great post Martin,
Some questions I have are:
I want to set the “approver” to a selected “resource manager” that was set from a drop down list on a PDP.
I have the GUID of that custom field.
All the branching examples I see use the read a list and set it to “assignedto” and I can’t for the life of me find one that sets the value to a single person without using a security group.
The Project Server Team does the same thing so it was no help either(contoso example).
You set it to the first person in the list? Anyways thanks for any help.
Maybe you know what “assignedTo” is looking for? It just says “string” but its looking for the xml representation of a user/list right? I have tried assignedto = “Domain\user” and it blows up also.
How would I set the assignedTo to say the project owner? Its not in a list, so I read into a variable and then try setting this to the “assignedTo” and the workflow blows up(line 1, char 1….xml)…
Hmm thanks for this info also. Great help. Im hoping the Project Server Team puts out some more examples.
Hi Mike,
Two good questions, both problems you mentioned can be solved, in fact I recently had need to do just that (ie pick an approver from a lookup-table selection).
The solution however is not necessarily so simple, in my case I had to create a custom activity (See CustomActivityWorkflow in the P14 SDK) which using the PSI converted a username into an actual usable name. Then feed this list of names into the SampleProposal2 “FormatApprovers(string[] list)” method and you can use the values for AssignedTo.
Unfortunately I can’t publish this code as it was written for a customer, but I can say that those two referenced SDK samples provided me with all the information I needed to solve this problem.
Hope that helps,
Martin.
Hi Martin,
It’s strange that there aren’t many posts about this, but it seems as if the “Comments” field (officeTask.Comments) from the default approval task is always null when trying to access it through the workflow. I’m trying to retrieve it in the checkExitConditions activity, and I’ve also tried to access it in the onTaskCompleted activity with no luck. Would you please point me in the right direction if you have any info on this? Thank you very much for the help