Dec 23, 2008

iLSP - SharePoint Designer “Call a Web Service” Action

“iLSP” – is the abbreviation for iLove SharePoint.

The “Call a WebService” workflow action is included in the iLSP -SharePoint Designer Actions 1.0 release. Installation see readme.txt.

The action supports SOAP 1.1, SOAP 1.2, basic and windows authentication.

Let’s go and call a built-in SharePoint web service – Lists.asmx and create a new List with the AddList operation.

  • Bring up SharePoint Designer and create a new workflow on an list with a “Title” and “Response” (Multiple lines of text – plain text) column.
  • Add the “Call a Web Service” action from the “iLove SharePoint” category

image

  • Configure the action as follows:
    • URL: http://[siteurl]/_vti_bin/Lists.asmx
    • SOAP Version: SOAP 1.2
    • SOAPAction: not needed for SOAP 1.2
    • Envelope:

<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<AddList xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>[%MyList:Title%]</listName>
<description>Created by iLSP action</description>
<templateID>100</templateID>
</AddList>
</soap12:Body>
</soap12:Envelope>

You can copy the SOAP 1.2 example request from http://[siteurl]/_vti_bin/Lists.asmx?op=AddList

      • For the <listName> insert a reference to the current item’s title.

image

      • As <description> enter “Created by iLSP action
      • Set the <templateID> to 100” = custom list

  • Response: create a new string workflow variable named “response” and assign it. The action will fill the variable with the response from web service call (xml string).
  • User: leave empty. Empty user = use default credentials.
  • Password: leave empty

Now the “Call a WebService” action is configured.

To check the response, we will write it in the “Response” column of the item using the built-in “Set field in current item” action. Set field to “Response” and “Value” to the above defined workflow variable “response”

image

Try it – Start the workflow on an item

The response:

image

The new list:

image

Because the raw response isn’t very useful, we now parse it using iLSP “Query XML” action. Place the action between the “Call a WebService” and the “Set field in current item” action.

  • Add the “Query XML” action to the workflow

image

  • Configure the “Query XML” action
    • Input: choose the above defined workflow variable “response
    • XPath: //*[local-name()='List']/@ID
      • You can use any valid XPath expression e.g. count(//*). Is the expression result is a single node it will write the node’s inner XML to the result variable. Is the result a node collection, it will merge all the node’s inner XML separated by an semicolon into the result variable. You should identify the node by the local name, because you can’t use xml namespaces.
    • Result: Create a new string workflow variable named “ListID” and assign it.

The “Query XML” action is now configured

Now modify the “Set field in current item” action so that the response column is set to the ListID variable.

image

Start the workflow again

Result:

image

THE END

21 comments:

Chanda said...

Christian,
Thanks for these great activites! I do have one question about the Call A Web Service activity - I am using that to call the UpdateListItems web service. I am able to add new items successfully, however the response I get back seems to just be the error code and not the full response that you see in your posting here. Can you tell me what I might be doing wrong? I would like to capture the full response in order to parse the ID of the newly created item. Thanks,
Chanda

Chanda said...

Christian,
Disregard my previous comment, the response is returning the full xml, I was just viewing it in email which only displayed the error code. When I viewed the source of the email it shows the full response. Thanks again!
Chanda

Maik Zeyen said...
This comment has been removed by the author.
Maik Zeyen said...

Hello Christian,
i want to add a list item to a list via web service. But everytime i get an 500 Internal Server error.
This only happens when trying to add an Item via UpdatelistsItem. Createing a new List, like discribed in your Post works. Any idea why adding an Item fails? here is my Soap 1.2 Code for adding:

?xml version="1.0" encoding="utf-8"?>
soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/env...">
soap:Body>
UpdateListItems
xmlns="http://schemas.microsoft.com/sharep...">
listName>Aufgaben
updates>
Batch OnError="Continue" ListVersion="1">
Method ID="1" Cmd="Update">
Field Name="ID">1
Field Name="Title">Joe
/Method>
/Batch>
/updates>
/UpdateListItems>
/soap:Body>
/soap:Envelope>

The Adress is the _vti_bin folder where the Application and this List are placed.

Thanks

Christian said...

Hello, I recommend troubleshooting with Fiddler (HTTP Monitor). Make the call with a C# Test App and monitor the Http Request and llok if there are any differences. You could also take a look into the SharePoint log file, maybe you'll find a more detailed error description.

bye, Christian

Anonymous said...

Christian,

The "Call a Web Service" function works great!
But I've got a timeout on web services during workflow which returns data after 5 minutes. Is there anyway to fix the "Error calling Web Service. The operation has timed out" issue?
Please enlighten me

Regards,
Justin Wong

Christian said...

Hi Justin, at the moment you would have to change the source code to change the client's timeout e.g. client.Timeout = 600000

Bye, Christian

Justin Wong said...

Thanks for the comment :)
Now, this is lovely!

Anonymous said...

This is a great and to have this in Sharepoint makes it even better. I have a question on "Query XML" action.

%bookstore%

%book%
%title lang="eng"%Harry Potter%/title%
%price%29.99%/price%
%/book%

%book%
%title lang="eng"%Learning XML%/title%
%price%39.95%/price%
%/book%
%/bookstore%

What would you put in the "XPath:' to get the result for ? Or is this Action specific to a Sharepoint list only? Thank you for any response.

Anonymous said...

Sorry for the double post! Arrghh.

This is a great and to have this in Sharepoint makes it even better. I have a question on "Query XML" action.

%bookstore%

%book%
%title lang="eng"%Harry Potter%/title%
%price%29.99%/price%
%/book%

%book%
%title lang="eng"%Learning XML%/title%
%price%39.95%/price%
%/book%
%/bookstore%

What would you put in the "XPath:' to get the result for price? Or is this Action specific to a Sharepoint list only? Thank you for any response.

Anonymous said...

Can you explain this?

Where does 'List' come from?

XPath: “//*[local-name()='List']/@ID”
You can use any valid XPath expression e.g. count(//*). Is the expression result is a single node it will write the node’s inner XML to the result variable. Is the result a node collection, it will merge all the node’s inner XML separated by an semicolon into the result variable. You should identify the node by the local name, because you can’t use xml namespaces.

Anonymous said...

I found the answer I was looking for //*[local-name()='']

Between the quotes put the node name.

Madhu said...

I am having trouble using iLove Sharepoint. I am unable to add activities to the workflow, when i do add , nothing seems to happen. I have copied the language

As suggested below and the results are the same.

You have to copy %commonprogramfiles%\Microsoft Shared\web server extensions\12\TEMPLATE\1033\Workflow\iLoveSharePoint_Activities_EN.ACTIONS in the specific language folder that you want to use. For example 1033 is english.

Madhu said...

resolved it by adding the in the web site i was using. I had included it the sharepoint central. thank you ....

Madhu said...
This comment has been removed by the author.
Madhu said...

Error calling Web Service. The remote server returned an error: (500) Internal Server Error.

I tried to run the webservice directly it runs as expected without any problems.





dateTime




I am not sure where i have gone wrong.

Chris said...

Love your iLSP pack of custom SPD actions! I can't figure out how to resolve an error and would appreciate any assistance.

After using the "Call a Web Service" action to call the GetListItems method of the Lists web service, the "Query XML" action is used to retrieve the total number of items returned in the XML response (i.e. the "ItemCount" attribute of the "rs:data" element). The workflow keeps throwing the error: "Error querying XML. Object of type 'System.String' cannot be converted to type 'System.Int32'."

How may I access the "rs:data" or "z:row" elements of most Lists web service responses?

Thanks

Chris said...

Workflow variable type was set to "List Item ID" rather than "String"... :(

Christian said...

The result type of this action is always a string.

Irene said...

Hello Christian,

if I tried to run the webservice directly it runs without any problems.
But if i run automatically when create an item i get the error:

"Error calling Web Service. The remote server returned an error: (500) Internal Server Error."
In the error log this error means

"Workflow Infrastructure 98d4 Unexpected System.NullReferenceException: Workflow association not found at iLoveSharePoint.Activities.StartWorkflowActivity"

Thanks,
Irene

Jeff said...

I am using Call A Web Service activity to call the UpdateListItems web service. Everything works fine except for updating date fields. When I pass a sharepoint date field value it does not update however when I hard code mm-dd-yyyy it works fine. I find it hard to believe that this web service activity and the actual lists.asmx cannot work together to update a date value using a date value from within sharepoint