I have tried to insert multiple items in to list

var s=[];
$.each(f, function(){
 var l = [];

                listName: "xxxx",                
                batchCmd: "New",
                valuepairs: s,
                completefunc: function (xData, Status) {


nothing works, I don't get error but an empty results tag is there a working way t do it ?


If you want to insert multiple new items into a SharePoint List then you have to use SPServices.SPAddMultipleListItems .

In your code you are using SPUpdateMultipleListItems, its used to to update multiple items in a list based upon some common characteristic or metadata criteria.

If you want to insert new items into a SharePoint list using SPServices, you can use the following code,

$.fn.SPServices.SPAddMultipleListItems = function(options) {

    var opt = $.extend({}, {
        webURL: "",         // [Optional] URL of the target Web.  If not specified, the current Web is used.
        listName: "",       // The list to operate on.
        batchCmd: "New",    // The operation to perform. By default, New.
        valuepairs: [],     // Valuepairs for the update in the form [[fieldname1, fieldvalue1], [fieldname2, fieldvalue2]...]
        completefunc: null, // Function to call on completion of rendering the change.
        debug: false        // If true, show error messages;if false, run silent
    }, options);

    var i;
    var fieldNum;
    var batch = "<Batch OnError='Continue'>";
    for (i = 0; i < opt.valuepairs.length; i&#43;&#43;) {
        batch &#43;= "<Method ID='" &#43; i &#43; "' Cmd='" &#43; opt.batchCmd &#43; "'>";
        batch &#43;= "<Field Name='" &#43; opt.valuepairs[i][0] &#43; "'>" &#43; opt.valuepairs[i][3] &#43; "</Field>";
        batch &#43;= "</Method>";
    batch &#43;= "</Batch>";

    // Call UpdateListItems        
        operation: "UpdateListItems",
        async: false,
        webURL: opt.webURL,
        listName: opt.listName,
        updates: batch,
        completefunc: function(xData, Status) {
            // If present, call completefunc when all else is done
            if (opt.completefunc !== null) {

}; // End $.fn.SPServices.SPAddMultipleListItems


| improve this answer | |
  • For everyone passing by: as a copy and paste of an already bad formatted and encoded piece of code, "&#43;" is equal to a plus (+) sign. – Christoffer Feb 6 '18 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.