Somsong


Sometimes this works fine and the status of my workflow is "in progress" other times the workflow status gets gets stuck on "starting". The weird part is, when it works fine an exception is thrown when I call StartWorkflow(), when no exception is thrown the status get's stuck on "starting".

Anyone have any ideas

Thanks,

-Somsong



Re: starting workflow programmatically using SPWorkflowManager.StartWorkflow method

Jon Flanders


What are you passing for parameters Even if your workflow doesn't need parameters you need to pass empty xml elements. Its been a few months since I've done this so I don't remember what the right schema or format is (I seem to remember that it depends on your feature xml definition)




Re: starting workflow programmatically using SPWorkflowManager.StartWorkflow method

Somsong

Hi Jon,

Here's my code:

Dim enc As New System.Text.UTF8Encoding
Dim buffer As Byte
() = enc.GetBytes(TextBox1.Text)
Dim site As New SPSite(http://PDCDSP02/0500061
)
Dim web As
SPWeb = site.OpenWeb
Dim folder As SPFolder = web.Folders("Inspection"
)
Dim file As SPFile = folder.Files.Add("http://PDCDSP02/0500061/Inspection/Test.xml"
, buffer)

file.Update()
Dim item As SPListItem = file.Item
item.Update()
Dim manager As
SPWorkflowManager = site.WorkflowManager
Dim workflow As
SPWorkflow

workflow = manager.StartWorkflow(item, item.ParentList.WorkflowAssociations(0), "", True)
item.Update()

I don't have an Initiation or Association form so I just pass in "" for the EventData parameter. I'm just not sure why it works sometimes and sometimes it doesn't.






Re: starting workflow programmatically using SPWorkflowManager.StartWorkflow method

Jon Flanders

I found that in my tests (this was the earlier CTP not the RTM) that not passing XML always caused the workflow to fail. When I attached a debugger to the ASP.NET worker process - the exception related to serialization of the input XML. So I started passing xml with empty element values and that worked.




Re: starting workflow programmatically using SPWorkflowManager.StartWorkflow method

Somsong

The exception I get is:

Exception from HRESULT: 0x8102009B

Here's my stacktrace of the exception:

at Microsoft.SharePoint.Library.SPRequest.AddWorkflowToListItem(String bstrUrl, String bstrListName, Int32 lItemID, Int32 lItemLevel, Int32 lItemVersion, Guid workflowPackageId, Guid& pWorkflowInstanceId, Guid workflowTaskListId, String bstrStatusFieldInternalName, Int32 lAuthorId)

at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflowElev(SPListItem item, SPWorkflowAssociation association, SPWorkflowEvent startEvent, Boolean bAutoStart, Boolean bCreateOnly)

at Microsoft.SharePoint.Workflow.SPWorkflowManager.<>c__DisplayClass1.<StartWorkflow>b__0()

at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state)

at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()

at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)

at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)

at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)

at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(SPListItem item, SPWorkflowAssociation association, SPWorkflowEvent startEvent, Boolean bAutoStart, Boolean bCreateOnly)

at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflow(SPListItem item, SPWorkflowAssociation association, String eventData, Boolean isAutoStart)

at WinAppTest.Form1.Button1_Click(Object sender, EventArgs e) in C:\Projects\pdc\R & D\Somsong P\WinAppTest\WinAppTest\Form1.vb:line 22

The weird part is, when I get this exception everything works as it should. When there is no exception the workflow doesn't start properly.





Re: starting workflow programmatically using SPWorkflowManager.StartWorkflow method

Tom Lake - MSFT

Since this post is specific to SharePoint you should ask your question at on one of the SharePoint forums found at http://www.microsoft.com/office/community/en-us/FlyoutOverview.mspx#15.





databaseforum