I'm developing sequential workflow for Sharepoint 2010. It starts at item creation and it has activities as follows: onWorkflowActivated, then createTaskWithContentType and onTaskChanged in while loop. onWorkflowActivated1 is bounded to field workflowProperties of type SPWorkflowActivationProperties, initialized with default constructor inline. createDraftTask in its MethodInvoking set tasks AssignedTo property with value retrieved from items field of type SPUser, on which the workflow was started. The problem is that all item fields except one (of type Choice) are null while running the workflow for the second and every next time, i.e. while creating second item on the list, which triggers another run of the workflow, workflowProperties.Item["fieldname"] is null, even though in web browser all values are visible and set. For the first item created on the list, it all seems fine. Code for retrieval items field is as usual:

object fieldValueFromGuid = workflowProperties.Item[ProcedureItem.ProcessOwnerFieldId];
object fieldValueFromWorkflowProperties = workflowProperties.Item["ProcessOwner"];
// this works usually when debugger is attached, in development environment
object fieldValueFromList = workflowProperties.List.GetItemById(workflowProperties.ItemId)["ProcessOwner"];

No matter if I use fields GUID or name in the indexer, both are null. Usually in the development environment, when debugger is attached, the third approach works. Any ideas what might be the reason? Thanks in advance for all suggestions


I think I found a reason for this problem. The thing is, that the workflow is configured to start once the item is added to the library and I am the one who adds a document. I do that in my custom page, that I used to replace traditional 'add new item' link. The code I execute on that page looks as follows:

SPFile procedureFile = library.RootFolder.Files.Add(newFileUrl, binFile, false);

pretty basic. SetitemFields method simply uses SPListItem indexer to set field values like this:

item[fieldName] = value;

The problem is, that when executing this line:

SPFile procedureFile = library.RootFolder.Files.Add(newFileUrl, binFile, false);

workflow starts. And it starts before all fields are set and item is updated (next two lines). A resolution for this, was to remove 'start at item creataion' on workflow and adding code for starting workflow programmatically. A similar issue was presented in this question, have a look at Mwolffys answer. Hope it helps to someone. Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.