Add new item using SPServices

Feb 9, 2011 at 1:29 PM
How can I add new item into SP list if one of the columns is lookup field.
<script type="text/javascript">
$(document).ready(function() {
    $("#SubmitMinutes").click(function() {
		var subject = $('#TextArea1').text();
		var message = $("#Select1 option:selected").text();
		CreateNewItem(subject, message);		


function CreateNewItem(subject, message) {
        operation: "UpdateListItems",
        async: false,
        batchCmd: "New",
        listName: "Objectives",
        valuepairs: [["Objective", subject], ["Attendee Headline=", message]],
        completefunc: function(xData, Status) {

		Attendee Headline:<select name="Select1" ID="Select1" style="width: 100%">
 <div align="left">
<textarea name="TextArea1" ID="TextArea1" rows="5"  style="width: 100%"></textarea>
	<div align="center">
		<input name="SubmitMinutes" id="SubmitMinutes" type="button" value="Submit" style="height: 21px; width: 50px">
                  <input name="ResetMinutes" type="button" id="ResetMinutes" value="Reset" style="height: 21px;width: 50px"></div>
Feb 9, 2011 at 2:28 PM

Hi Armino,

When one of the fields in a SharePoint list is a lookup value you have to update it with the ID and the value, like:

Read this like: 'TextHere' is the value of the lookup column which is shown in the referenced list. '4' is the ID of the item in the original list.

Regards, Anita

Feb 9, 2011 at 2:39 PM

Thank you I'll try it

Feb 9, 2011 at 2:55 PM

Yep - you will likely need to do a GetListItems from the look up list, where your camlquery uses the lookup value, and your camlview the ID field. Return the ID, a little concatenating and you are on your way!

Jan 13, 2012 at 7:04 PM
Edited Jan 13, 2012 at 7:05 PM

I have a similar problem, however the lookup field has multiple entries as opposed to just one lookup, so for example in my UpdateListItems SPServices call my updates section has "<Field Name='TasksCompleted'>" + completed + "</Field>" where completed is a string like "ID1;#TaskName1 ID2;#TaskName2 .....". Is each ID;#TaskName pair supposed to be separated by something special? Or is there another way of doing this?



Jan 13, 2012 at 7:07 PM


It's not totally clear from your description, but generally multiselect lookup column values will look like this: