Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firing a SharePoint Workflow by updating a list item through List Webservice

I am developing, a simple SharePoint Sequential Workflow which should be bound to a document library. When associating the little workflow to a document library, I checked these options

  • Allow this workflow to be manually started by an authenticated user with Edit Items Permissions.
  • Start this workflow when a new item is created.
  • Start this workflow when an item is changed.

Now I upload a document to this library and the workflow starts and for instance sends a mail. It completes and everything is fine.

When I select Edit Properties on the new Item and save a change, the workflow is fired again. Absolutely what we expected.

Even when copying a new Item into the library with help of the Copy.asmx Webservice, the workflow starts normally.

But now I want to update the item via the SharePoint WebService Lists.asmx.

My CAML goes here:

<Method ID='1' Cmd='Update'>
  <Field Name='ID'>1</Field>
  <Field Name='myDummyPropertyField'>NewValue</Field>
</Method>

The Item is being updated (timestamp changed and a dummy property, too) but the workflow does NOT start again.

This behaviour is reproducable on our development and test system.

Checking the error logs (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS) I discovered a strange error message:

09/25/2008 16:51:40.17  w3wp.exe (0x1D94)                           0x1D60  Windows SharePoint Services     General                         6875    Critical    Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver in Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Additional information is below.  : The object specified does not belong to a list.

Anybody who can confirm this behavior? Or any solution hints?


I am keeping you informed of any developments on this topic.

like image 280
Johannes Hädrich Avatar asked Sep 25 '08 15:09

Johannes Hädrich


People also ask

What are three types of SharePoint workflows?

There are five commonly used Workflows that can be set up within SharePoint: Approval Workflows, Status Workflows, Notification Workflows, Automation Workflows, and Custom Workflows.

How do I edit a SharePoint Workflow list?

To edit an existing workflow in SharePoint Designer 2010, in the Navigation pane, click Workflows. In the main pane, right-click the desired workflow, and click Edit Workflow. To copy and modify a reusable workflow in SharePoint Designer 2010, in the Navigation pane, click Workflows.


1 Answers

Finally, we got through the support services processes at Microsoft and got a solution!

First, Microsoft stated this to be a bug. It is a minor bug, because there is a good workaround, so it may take some longer time, until this bug will be fixed (the support technician said something with next service pack oder next version (!)).

But now for the problem.

The reaseon

Let's take a look at the CAML code from my question:

<Method ID='1' Cmd='Update'>
  <Field Name='ID'>1</Field>
  <Field Name='myDummyPropertyField'>NewValue</Field>
</Method>

For any reason the Workflow Manager does not work with the ID, we entered in the second line. Strange, all other SharePoint commands are working with the ID, but not the Workflow Manager. The Workflow Manager works with the "fully qualified" document name. So, because we had no clue and didn't entered any fully qualified document name, the Workflow Manager defaults to the name of the current document library. And now the error message begins to make sense:

The object specified does not belong to a list.

Of course, the object (document library) does not belong to a list, it IS the list.

The solution

We have to add one more line to our CAML Query:

<Field Name='FileRef'>/sites/mySite/myDocLib/myFolder/myDocument.txt</Field>

The FileRef passes the fully qualified document name to the Workflow Manager, which - now totally happy - starts the workflow of the item.

Be careful, you have to include the full absolute server path, omitting your server name (found for example in ServerRelativePath property of your SPItem).

Full working CAML Query:

 <Method ID='1' Cmd='Update'>
    <Field Name='ID'>1</Field>
    <Field Name='FileRef'>/sites/mySite/myDocLib/myFolder/myDocument.txt</Field>
    <Field Name='myDummyPropertyField'>NewValue</Field>
  </Method>

The future

Perhaps this undocumented behaviour will be fixed in one of the upcoming service packs, perhaps not. Microsoft Support apologized and is going to release an MSDN Article on this topic. For the next month I hope this article on stackoverflow will help developers in the same situation.

Thanks for reading!

like image 172
Johannes Hädrich Avatar answered Sep 22 '22 02:09

Johannes Hädrich