Web Services are quite handy, but some of the data that gets returned can look like giberrish. This is especially true when you are dealing with XML that gets returned.
A scenario I came across recently, was getting a list of SharePoint users that are in a SharePoint group. This is possible via the SharePoint UserGroup web service – http://msdn.microsoft.com/en-us/library/ms772647.aspx. Specifically, the GetUserCollectionFromGroup web method.
In order to use the information from this web method, we need to parse the XML returned, and extract the information we need.
What I have found to be the easiest way to start working on this type of issue, is to configure the Call Web Service action to make this call and store the result in a text variable.
Now that we have the resulting XML in a text variable, we want to see what it looks like. You can’t log it to the workflow history, because there are just too many characters in it.
nstead, I use a Send a Notification action and configure it to send the initiator of the workflow an email with the XML as a file attachment.
To add an attachment to a Send a Notification action, you simple click on the “Show Attachments” link. Then click on the “Add Attachment” link and it will give you a pop up that will allow you add an attachment to your notification.
You then click on the “New File” radio button, type in a filename you want for your attachment. I usually use something like “xml.txt”, as it lets me easilly open the file in notepad.
Click on the Insert Reference button, and you can insert your text variable which contains your XML into the attachment.
Now we can publish the workflow, run it and you should get an email with the attachment. You can then open it, and figure out the best way to use the Query XML action to parse the data that you need.
This is what the email looks like :
As you can see, the attachment is 605 bytes. A lot bigger than what is allowed in a Workflow History message (255 bytes).
As I’m attaching this as a text file, if you open it up, it’s not going to be very pretty. But if you save it to your local disk and rename it to XML and open it in something like Internet Explorer, it will look something like this :
Now it’s easy to see that we are getting the data we expect, and also what format that data is in, so we know whether to use XSL or XPath in our Query XML action.
What this complicated workflow looks like :
Note : Workflow has been updated to include a few Query List actions to retrieve the Login Name, Email and Name from each User node that we have received from the Web Service call.
Note : this doesn’t have to be specific to XML or even responses from Web Services. It can be used in any situation you have some data you want to see in a complete form, but it is not possible via the workflow history.
Get Users in a Group Workflow download