.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Cutomized Approval code approves first task but can't approve second task

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :C#

My workflow has two steps. Each step starts an OOTB approval workflow.  I submited approval/reject from  infopath form. 

The code below worked fine on the first workflow task.  The 1st task was approved and completed and  the 2nd task was created.  However when I submited the approve again for task 2.  Nothing happened.  I didn't get error message and the AlterTask returned true. But the fields were not updated and the workflow was not moving. The task wasdecided by this value 'workflow.Tasks[1]'

SPSite site = new SPSite("http://servername/");
using (SPWeb web = site.OpenWeb())
 SPList list = web.Lists["TestList"];
 SPListItem item = list.GetItemById(22);
 SPWorkflow workflow = item.Workflows[0];
 SPWorkflowTask task = workflow.Tasks[i];

 Hashtable ht = new Hashtable();    
 ht[SPBuiltInFieldId.Completed] = "TRUE";
 ht["Completed"] = "TRUE";
 ht[SPBuiltInFieldId.PercentComplete] = 1.0f;
 ht["PercentComplete"] = 1.0f;
 ht["Status"] = "Completed";
 ht[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new CultureInfo((int)task.Web.Language, false), Strings.WorkflowStatusCompleted, new object[0]);
 ht[SPBuiltInFieldId.WorkflowOutcome] = "Approved";

View Complete Post

More Related Resource Links

Infopath form return XMl code during workflow task


1.     Review 7777.xml.

2.     Perform the specific activities required for this task.

Use the Edit this task button to mark the task as completed. (If you cannot update this task, you might not have access to it. Click here to request access.

Create a Outlook Task from Custom WebPart in Code



I have a requirement to create a Outlook Task , from a custom webpart through code .

Is this possible?

has any body tried this , if yes can you please give me an insight on how to acheive it.

Some sample Code would be highly appreciated.



Task doesnt have the approve button

Finally I was able to start runing my workflow, it starts ok, and then it generates a task, but when I go to the task, it doesnt have the Approve or Reject buttons, What am I missing? www.sharepoint2010blogger.com Follow me on Twitter <<<

Claim Task programatically / in code?

When a workflow task is assigned to a SharePoint Group, a user may click on the 'Claim Task' button near the top of the task form, or they can just start work on the task and not claim it. Claiming a task executes the OnTaskChanged event as does any change to the task form. Is it possible to claim a task using code ?  I already know who is executing the task (executor) ... and I want to claim the task on their behalf if it is not already claimed. How can I : claim a task using code determine if a task is already claimed using code Thanks for any pointers

Approval workflow is not passing task instructions to workflow task page (WrkTaskIP.aspx)

Hi, Very weird issue. Never happened before. I have Document Approval workflow, based on built-in approval workflow, which is available in document libraries of every site in the site collection. You might know that when you kick off approval (even collect feedback) workflow, you can enter task instructions, which will be passed on to the workflow task page (WrkTaskIP.aspx), and also included in the email, which will be sent to approvers (reviewers in case it is a collect feedback workflow). I know that the users used to enter task instructions, and before, it was appearing in the workflow task page where you approve/reject it. Recently, they noticed that the task instructions textbox was being empty, though the instructions were being entered when the workflow was started. Moreover, it stopped showing task instructions for other tasks that existed for a long time. BTW, this is not the same in every environment we have, but I could not find any difference in the settings when I compared them. Has anybody faced this problem? Please help if you know the solution. Thank you!!! Regards, R.D.M.

OOTB Approval Workflow SharePoint 2010 - Blank "Requested By" field appears in Task Item edit/view f



I am having a simple OOTB  approval worflow associated to the simple document library. Task is created when an document is uploaded to the library.  When I click the task item in task list, I see a blank field "Requested By"  right below the "Status" column and I am unable to understand from where this field is coming and how to populate this field. Any help would be great...

How can I edit the link to the document in a Approval Task email?


With the 2010 out of the box Approval workflow, the emails and tasks work just great, however, when a user receives the email, the instructions look like this:


To complete this task:
2. Perform the specific activities required for this task.
3. Use the Open this task button to mark the task as completed. (If you cannot update this task, you might not have access to it.)


Currently, we are using a friendly url for our users, in order to access their SharePoint site.  The <LINKED DOCUMENT> when clicked on, gives them an error and doesn't take them to the actual document in the SharePoint site, because of the fact that we are using a different url name for the site.

If there any way I can edit this auto-generated email so that the links will always be to the friendly url of our SharePoint site with each document?


Thanks in advance!

error code:0xC0024104 source: Reporting Task for subplan- Description: the execute method on the tas


I am getting following error when running maintenance plan under schedule job. I am getting this error for maintenance cleanup task.  The job is not failing all the time but alternate weeks. I created same maintenance plan on test server(same configuration as PROD) and Maintenance cleanup task related job failed for first time and running fine from there. I don't know why it is causing failed. I checked maintenance plan history and it show successful each time. even i checked manually it deleted all the report files related to maintenance plan. History Cleanup task and Maintenance Cleanup task should not be created on same Maintenance Plan?....I know SQL Server 2005 had some problem with maintenance plan creation before SP2.

Update Approval Workflow task status


Hello All

I am trying to update the task status automatically after a list item is approved without much luck. I need to set the task status to "completed" without having to manually hitting the "complete task" button, so the next person in line can approve the list item.

How can I change the status of a task using SharePoint Designer 2010?

In my SharePoint Designer task editor I have:


if Current Item:Approval Status equals 0;Approved

---I need to add a line in here that updates the task status to "completed"

Assign Approve list item to User2



Thank you all in advance.



Email blast software or c# code to accomplish task


Looking for suggestions on email blast software or a way to write in c# something that we can query access database and send out individual emails using 3 seperate templates based on the users selection.

basically users have been signing up to receive an email later in the year.. there are 3 possible email templates that are designed and will be sent based on what the user selected. So when the time comes, we need to take and query the access database and send an email to the user with the template they picked.

I see alot of software packages, but cost more than what we can spend(no budget), so we need something simple and free that can be scheduled to send on certain day and time. Or if there are any tutorials on creating something to do this, doesnt need to be fancy, 



Approval Workflow : Getting the name (or unique ID) of the item being approved in the infopath Task


I need to display the name/title of the item being approved in the infopath task form that is viewed by the approvers. How can I achieve this? The data fields in the Primary data connection seem to correspond to task item and not the item being approved itself.

Thanks in advance!

SharePoint 2010 Approval Workflow email is not showing link to Workflow Task list



I have created an out of box Approval workflow in SharePoint 2010. I am receiving email with below information

Task assigned by Chinna Malipedu on 10/7/2010.

Due by 1/1/0001

Approval started by Chinna Malipedu on 10/7/2010 11:43 AM
Comment: Approve



To complete this task:
1. Review SharePoint2010.
2. Perform the specific activities required for this task.
3. Use the Open this task button to mark the task as completed. (If you cannot update this task, you might not have access to it.)

But I need to go to Workflow Task List by clicking 3 item "Use the Open this Task" , this is not a link here

or I want like "Edit this task to mark the task as completed."  Edit this task should link to Task List

How to do this? do i missing any configuration?

I have successfully done the same  in MOSS 2007.                                                               Is there  any extra&n

Sharepoint 2010 Approval Workflow "Open this task" link not functioning


When I am clicking on "Open this task" link in outlook 2010 i am getting error as "Access to the floowing form required". Please help me out to resolve the issue..






Copying approval from Workflow task to List Item.


I have a system for entering info into sharepoint.  When the info is first entered, the list info is sent to the manager for approval using the workflow approval process.  This work, the email goes through, and then is approved on the workflow, but we have the require content approval checked, and this approval stays on pending.  I am trying to do a look up on the task list, and then approve or reject based on that.  It is not working.  The If statement always is ok, and then it is approved, even if i set reject.  Can anyone help me with this?


For the workflow lookup, the Field Data to Retrieve is

DataSource is the Tasks list for the workflow

Field from source is Approval Status


The Find the list Item is

Field is Workflow Item ID

Value is Current Item:ID


I am using this info to try to pull the approval status of the workflow and then based on

that set the approval of the list item.



How to approve SharePoint workflow task from mobile?



I have an intranet site for change control management system. Approval workflow is associated with the list. On new request creation or editing any item, approval workflow task is created and mail notifications are sending to the concerned person. Now approving manager login to the portal and approve the task.

Now they are asking to enable mobile access of those pending task and approve the same from mobile. How do I achieve this?

They DO NOT want to expose this site to internet or extranet.


thanksArup MCTS - SharePoint

Play Sudoku Online

create task using c# code in state machine workflow


hi all;

i need to create task activity using c# code under specific condition to more than one person (parallel task)

any idea and if u please could u support me with samples as i'm new in workflow using VS2010


thanks in advance

Approval Workflow - Assign task to a SharePoint Group



I have created a oob approval workflow and upon requirement, need to assign the task to a group of people, so created a SharePoint group under that site and selected this group under approvers. Selected assign single task to each group entered (do not expand groups) as this is what I need exactly. One person in that group is going to approve the task and the remaining members will work as backups that means for some reason the first person is not available for approval any one from the rest of the group will claim the task. When I test this, SharePoint is sending the first email stating workflow has been started and then another mail with the task to approve and the final email saying workflow is completed after completion of all tasks. These 3 emails are expected until now, but sharepoint is also sending two more additional emails even after completion of the task saying 'Task has been changed' to all the members in the group, these two are not needed in any way as workflow has already been finished. Not sure why these additional email alerts are triggering. Users will be annoyed to see all these unnecessary alerts if this is how it works.

Any idea on how to fix this?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend