Wednesday, January 19, 2011

AgilePoint ASP.NET - base.CompleteWorkItem() not working

AgilePoint Web Project provides a framework for your to develop your custom workflow web application with AgilePoint capability. In come cases, the base.CompleteWorkItem() at your aspx page does not complete the work items. Here is an alternative to call the CompleteWorkItem method.

Here is your code which calls the base.CompleteWorkItem():

private void SubmitClick(bool Approved)

{

NameValue[] nvs = new NameValue[] { new NameValue("/pd:myFields/pd:Approval", Approved) };

base.SetCustomAttrs((string)base.GetWorkObjectID(), nvs);

base.CompleteWorkItem();

....

}

You can override the CompleteWorkItem() method and call --> this.CompleteWorkItem() :

Sample Override

You may call the CompleteWorkItem() method from the WFWorkflowService object (it's represented by the variable api below) directly. Another benefit to do this is, you may inspect the WFEvent object returned from api.CompleteWorkItem() to see if it is failed or succeeded. (Note: base.CompleteWorkItem() return void, so you can't inspect the event status)

Please note that the loop in below code that waits for 1 second and checks the event status again is for testing or debugging purpose only. If you put this code in production every time you call the CompleteWorkItem() method, it might cost performance issue.

protected override void CompleteWorkItem()

{

// base.CompleteWorkItem(); <-- do not call the base method

if (base.GetWorkItemID() == null)

{

Logger.WriteLine("Lost Work item ID from ViewState[WID]...");

// ToDo: You might want to provide an alert message here

}

base.WriteBindingControls();

if (base.GetAPI() == null)

{

Logger.WriteLine("Lost API from the SessionState...");

// ToDo: You might want to provide an alert message here

}

IWFWorkflowService api = base.GetAPI();

WFEvent evt = api.CompleteWorkItem(base.GetWorkItemID()); // Submit Complete Work Item

System.Threading.Thread.Sleep(1000); // 1 sec wait

WFEvent evtUpdt = api.GetEvent(evt.EventID);

while (evtUpdt.Status == WFEvent.SENT) // Inspect event status

{

System.Threading.Thread.Sleep(1000); // 1 sec wait

evtUpdt = api.GetEvent(evtUpdt.EventID);

}

if (evtUpdt.Status == WFEvent.FAILED)

{

Logger.WriteLine("Failed Work Item Completion request xxxxx - Check AP Server Log");

// Potential errors that can be gleaned from the AP Server Log are:

// 1. Ownership of the workitem - requester is different from the assigned user

// i.e. Failed to complete the task due to ownership with Request User={0} and Assigned User={1}

// 2. UserID for the work item is null

// i.e. Failed to complete the task with WorkItemID={0} because there is no assigned user.

// 3. Work Item has null Activity Instance ID

// i.e. Failed to create work item because the activity is not found with process='{0}',ActivityID={1}, and Sender='{2}'

// 4. this work item depends on child work items

// i.e. Failed to complete work item because he work item is trying to be completed depends on child work item(s), Process='{0},{1}/{2}/ID={3}' WorkItemID='{4}', Child WorkItemID='{5}'

}

else if (evtUpdt.Status == WFEvent.PROCESSED)

{

Logger.WriteLine("Processed Work Item Completion request xxxxx");

}

}

No comments:

Post a Comment