cancel
Showing results for 
Search instead for 
Did you mean: 

Inserting an item with web service call (people)

Automation Master
Automation Master
6 4 5,375

I had a requirement whereby no users would have access to input into a list in SharePoint, but that my workflow needed to create an item in it.  Perfect for using a web service call with a service account I thought!

I created a service account and added the credentials into my workflow constants for the site.

To start with in my workflow I created a build string action to create the XML to pass into the web service call:

vMTextBatchXML.PNG

Originally I only needed to add text fields in to the list, so I hooked up my web service call as follows:

  • Call web service action
  • URL = Web URL/_vti_bin/lists.asmx
  • Username and password = managed credentials input earlier of the service account
  • web method = UpdateListItems
  • Editor mode = SOAP builder
  • listName (string) = Requests
  • updates (xml) = vMTextBatchXML (the XML we created earlier)

I ran the workflow and it created the item perfectly.  I was super happy with this.

Then the requirement changed (development wouldn't be the same without a spot of scope creep ) - I needed to take the requester from the originating list and pass it to the people picker field of the destination list.  Easy I thought.  I added my field name into the XML in the build string and ran again.  WRONG.  it kept failing and I couldn't work out why.  I tried everything possible in the people picker value to pass across, but it wouldn't work.

What I didn't know until now is that the XML wanted me to pass the person or group field in this format:

<userID>;#<userLoginName>

where userID is the local ID of the user being passed in the web service call.

So then I needed to work out how to get the userID to be able to pass my value in the correct format.

What I did is here (but please shout if there is an easier way):

  • Call web service action
  • URL = Web URL/_vti_bin/usergroup.asmx
  • Username and password = managed credentials input earlier of the service account
  • web method = GetUserInfo
  • Editor mode = SOAP builder
  • userLoginName (string) = item property requester
  • Web service output, store result in = vMTextXMLOutput

So now I had the output of the web service call for the requester GetUserInfo.

I then used Query XML action to pull out the ID:

QueryXML.PNG

So now I had the user ID I could revisit my original build string action and pass the user in the format required.

I have written this here so that I can revisit next time I need to use this.  I don't know about you guys but I am always thinking to myself, "I know I have done that before, but where is it!!" so thought this might be an easier option for me!

Please let me know if anyone has taken a different approach for this.  I searched this community and google for answers when I was stumped but I couldn't find anything - but you never know if you search the correct terms!

Hope this helps someone, if not I know it will help me in the future!

4 Comments
Automation Master
Automation Master

reg UserID: you should be able to get it eg. with set variable action if you configure return type to do so.

Automation Master
Automation Master

can you expand on that Marian as I don't understand your response at this point.

Automation Master
Automation Master

I meant following

Automation Master
Automation Master

ah amazing thanks I will check that out