UpdateListItems does not appear to be working

Jan 26, 2015 at 1:39 PM
I have an issue where, when I try to use UpdateListItems, it only works for the Title field, and nothing else. As well, when I try to include more than the Title field, it won't even enter the item into the list.


The below code will not make any entry into the list:
$().SPServices({
    operation: "UpdateListItems",
    async: false,
    batchCmd: "New",
    listName: "mentoringList",
    valuepairs: [["Title", userName], ["titleAndOrRank", candidateTitleAndOrRank]],
/*
                 ["Title", userName],
                 ["titleAndOrRank", candidateTitleAndOrRank],
                 ["name", candidateName],
                 ["jDirectorate", candidateDir],
                 ["email", candidateEmail],
                 ["phone", candidatePhone],
                 ["yearsAtJob", candidateYearsAtJob],
                 ["Seeking", candidateSeek],
                 ["genderPref", candidateGenderPref],
                 ["mentorDescription", candidateMentorDescription],
                 ["comments", candidateComments]],
*/
    completefunc: function (xData, Status) {
        alert("Data Saved! and Please check you List");
        window.close();
    }
});
The below code will only enter the username into the list:
$().SPServices({
    operation: "UpdateListItems",
    async: false,
    batchCmd: "New",
    listName: "mentoringList",
    valuepairs: [["Title", userName]],
/*
                 ["Title", userName],
                 ["titleAndOrRank", candidateTitleAndOrRank],
                 ["name", candidateName],
                 ["jDirectorate", candidateDir],
                 ["email", candidateEmail],
                 ["phone", candidatePhone],
                 ["yearsAtJob", candidateYearsAtJob],
                 ["Seeking", candidateSeek],
                 ["genderPref", candidateGenderPref],
                 ["mentorDescription", candidateMentorDescription],
                 ["comments", candidateComments]],
*/
    completefunc: function (xData, Status) {
        alert("Data Saved! and Please check you List");
        window.close();
    }
});
The commented out section is all the fields I'm trying to save in the SharePoint List.
Jan 26, 2015 at 7:08 PM
Maybe this will help. Here is what I got from the xData.repsonseText:
    xData.responseText  "<?xml version=\"1.0\" encoding=\"utf-8\"?>
                                                                <soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
                                                                     <soap:Body>
                                                                         <UpdateListItemsResponse xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">
                                                                             <UpdateListItemsResult>
                                                                                 <Results>
                                                                                     <Result ID=\"1,New\">
                                                                                         <ErrorCode>0x00000000</ErrorCode>
                                                                                         <ID />
                                                                                             <z:row ows_ContentTypeId=\"0x0100915E03EA3A6D854884AF3DFFF345BABE\" ows_Title=\"Dewell Matthew M CONTR USSTRATCOM/J76\" ows_ID=\"11\" ows_ContentType=\"Item\" ows_Modified=\"2015-01-26 14:00:49\" ows_Created=\"2015-01-26 14:00:49\" ows_Author=\"634;#Dewell Matthew M CONTR USSTRATCOM/J76\" ows_Editor=\"634;#Dewell Matthew M CONTR USSTRATCOM/J76\" ows_owshiddenversion=\"1\" ows_WorkflowVersion=\"1\" ows__UIVersion=\"512\" ows__UIVersionString=\"1.0\" ows_Attachments=\"0\" ows__ModerationStatus=\"0\" ows_LinkTitleNoMenu=\"Dewell Matthew M CONTR USSTRATCOM/J76\" ows_LinkTitle=\"Dewell Matthew M CONTR USSTRATCOM/J76\" ows_SelectTitle=\"11\" ows_Order=\"1100.00000000000\" ows_GUID=\"{BBBB8221-AB98-4C64-862E-C0F13ECA1EF4}\" ows_FileRef=\"11;#sites/mentoring/sample/Lists/MentoringList/11_.000\" ows_FileDirRef=\"11;#sites/mentoring/sample/Lists/MentoringList\" ows_Last_x0020_Modified=\"11;#2015-01-26 14:00:49\" ows_Created_x0020_Date=\"11;#2015-01-26 14:00:49\" ows_FSObjType=\"11;#0\" ows_PermMask=\"0x7fffffffffffffff\" ows_FileLeafRef=\"11;#11_.000\" ows_UniqueId=\"11;#{95716BD8-A59C-43E4-BB61-C89699FBFF00}\" ows_ProgId=\"11;#\" ows_ScopeId=\"11;#{14E0650B-4640-4E2C-A1B9-E216A2643FF7}\" ows__EditMenuTableStart=\"11_.000\" ows__EditMenuTableEnd=\"11\" ows_LinkFilenameNoMenu=\"11_.000\" ows_LinkFilename=\"11_.000\" ows_ServerUrl=\"/sites/mentoring/sample/Lists/MentoringList/11_.000\" ows_EncodedAbsUrl=\"https://vela.stratcom.mil/sites/mentoring/sample/Lists/MentoringList/11_.000\" ows_BaseName=\"11_\" ows_MetaInfo=\"11;#\" ows__Level=\"1\" ows__IsCurrentVersion=\"1\" xmlns:z=\"#RowsetSchema\" />
                                                                                    </Result>
                                                                                </Results>
                                                                            </UpdateListItemsResult>
                                                                        </UpdateListItemsResponse>
                                                                    </soap:Body>
                                                                </soap:Envelope>"   String
Coordinator
Jan 26, 2015 at 11:06 PM
Edited Jan 27, 2015 at 2:32 PM
The response you show in your second post shows a successful update ( <ErrorCode>0x00000000</ErrorCode>).

My guess is that you don't have the InternalName correct for at least one of your other columns. Since the response doesn't show all of the columns, you'll need to look them up. For instance, the second column you're trying to update is "titleAndOrRank", but that's not in the response.

M.
Jan 27, 2015 at 11:30 AM
Hello Marc,

Thank you for the response. I tried entering something as simple as:
$().SPServices({
    operation: "UpdateListItems",
    async: false,
    batchCmd: "New",
     listName: "mentoringList",
     valuepairs: [["Title", userName], ["name", "Matt"]],
/*
                  ["Title", userName],
                  ["titleAndOrRank", candidateTitleAndOrRank],
                  ["name", candidateName],
                  ["jDirectorate", candidateDir],
                  ["email", candidateEmail],
                  ["phone", candidatePhone],
                  ["yearsAtJob", candidateYearsAtJob],
                  ["Seeking", candidateSeek],
                  ["genderPref", candidateGenderPref],
                  ["mentorDescription", candidateMentorDescription],
                  ["comments", candidateComments]],
 */
     completefunc: function (xData, Status) {
         alert("Data Saved! and Please check you List");
         window.close();
     }
 });
And that didn't even work, i.e. it did not make any entry in the SharePoint list. Again, if I just use [["Title"], userName]]; it works fine. It seems when I add more than one item into the valuepairs, it does not work, i.e. no entry at all is made in the list, not even the username.

Along those lines though, I have tried just using the name for the valuepairs entry, i.e. valuepairs: ["name", "Matt"]], with no luck.

Any more ideas?

Thank You so much for your help.
Coordinator
Jan 27, 2015 at 2:34 PM
I don't see "name" as a column in the results above, either. Are you sure that you have the right InternalName for the column(s)? In fact, I don't see any of the columns that you want to update in the results above. Are you trying to update the right list?

M.
Jan 27, 2015 at 3:51 PM
Hello Marc,

Thanks again for your response. I think I finally got it figured out. When I was trying to pull some sample data from the list, it would not even pull anything, so I set the ViewFields to <ViewFields properties='true' />. I then got a better picture of how the data was being stored
ows_Title='Matthew'
ows_userID='Maj. Sgt.'
ows_Name='Billy Bob'
ows_Directorate='J76'
ows_email='Matt@booYah.com'
ows_phone='333-3333'
ows_yearsAtJob='1.00000000000000'
ows_seeking='Mentor'
ows_genderPref='Both'
ows_mentorDescription='Yadda! Yadda! Yadda!'
ows_comments='Testing 1 2 3 4'
That struck a light on in my head. Your were right. I just didn't know where and how to check the InternalName, and I wasn't trying any other fields. I set the fields to the proper name, and not the names showing in the SharePoint List titlebar. It all seems to work now.

Thank You!
Coordinator
Jan 27, 2015 at 4:05 PM
Edited Jan 27, 2015 at 4:12 PM
Excellent!

A couple of [relatively] easy ways to get the InternalNames:
  • Go to List Settings and hover over each column. You'll see the InternalName after "&Field=". Note that the name will be double encoded. For example, if a field's DisplayName is "My Country", you'll see "My%5Fx0020%5FCountry". The actual internalName is "My_x0020_Country".
  • Call GetList, which will return the list's schema and inspect the results in a debugger. Example:
$().SPServices({
    operation: "GetList",
    listName: "MyList"
});
M.
Marked as answer by trout0525 on 1/27/2015 at 10:11 AM
Jan 27, 2015 at 5:14 PM
Edited Jan 27, 2015 at 5:16 PM
Note to just clarify your solution a bit, as to finding the field names, to see the field names:
  • Go to List Settings and hover over each columns name and look at the status bar to see where the link goes. You will see the name listed at the end of the URL, and then you can go from there.
Thanks again.
Coordinator
Jan 27, 2015 at 5:26 PM
I'm going to do a blog post with that info. People ask questions about it all the time, whether they are using SPServices, REST, or CSOM.

M.