Question

I've got some failing while trying to start my workflow. It's a workflow with some approval tasks on it. That's what happens whenever I try to start it programmatically. I get no errors. Everything goes fine. However, just when the first approval process walks in, SharePoint starts the approval task as it was told to do. Then, right after this task gets cancelled, the workflow crashes. I don't know why. On the workflow history page, I got this information "Error-The workflow could not update the item, possibly because one or more columns for the item require a different type of information.-Unknown error". PS: Whenever I start this same workflow manually (through the workflow's start page) with same account, same list item, same everything, it gives me no trouble. I tried digging through the log to find something that would help me to solve this but no success. Do you have any guess why I can't start it programmatically without facing this?

My code:

        using (SPWeb Web = SPContext.Current.Web)
        {
            SPList myList = Web.Lists["MyList"];

            SPListItem listItem = myList.GetItemById(ListItemId);

            //Get workflow’s Id             
            Guid workflowId = GetRelatedWorkFlowId(Web);

            foreach (SPWorkflowAssociation workflow in myList.WorkflowAssociations)
            {
                if (workflow.Id == workflowId)
                {
                    using (SPSite site = Web.Site)
                    {
                        Web.AllowUnsafeUpdates = true;
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            site.WorkflowManager.StartWorkflow(listItem, workflow, workflow.AssociationData);
                        });
                    }
                }
            }
        }
Was it helpful?

Solution

I was trying to do all of this from a Generic Handler (.ashx) and since to start a Workflow it does postback it was crashing my workflow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top