Quantcast
Channel: jQuery Library for SharePoint Web Services
Viewing all articles
Browse latest Browse all 6517

New Post: SPUpdateMultipleListItems Item limit

$
0
0
Hey Mark...
Here you go... Took a little while for me to find it (have not touched that project in over 1.5 years) and I had to make a few modification to remove specific dependencies on the original implementation, but should work...
function bulkUpdate (options) {
    
    // TODO: When resolveing Deferred or calling user's callback, need to find a way to provide the input params (xData) in the same format as the one used by SPServices.
    
    return $.Deferred(function(dfd){
        
        var opt = $.extend(true, {},
                    {
                        updates:    [],
                        batchSize:  100,
                        SPServicesOptions: {
                            operation: 'UpdateListItems',
                            async:      true
                        }
                    },
                    options
                );
        
        $.extend(
            opt,{
                _completeFunc:      null,
                _xData:             null,
                _xDataResultsEle:   null,
                _status:            'success',
                _lastIndex:         -1,
                _totalUpdates:      0
            });
        
        opt._totalUpdates = opt.updates.length;
        
        if (!opt._totalUpdates) {
            dfd.resolve();
            return;
        }
        
        // If caller defined a callback on SPServices, store it.
        if ($.isFunction(opt.SPServicesOptions.completefunc)) {
            opt._completeFunc = opt.SPServicesOptions.completefunc;
        }
        
        // Create the SPServices completefunc.
        opt.SPServicesOptions.completefunc = function(xData, status){
            
            // If there was a communications error, then no point in
            // continuing... error now and resolve Deferred.
            if (status === "error") {
                
                // If user had defined a callback, then call it now
                if ($.isFunction(opt._completeFunc)) {
                    opt._completeFunc.call($, xData, status);
                }
                
                dfd.rejectWith($, [xData, status]);
                return;
            }
            
            // If we did not yet create a response msg object, do it now
            if (opt._xData === null) {
                opt._xData = $(xData.responseXML);
                opt._xDataResultsEle = opt._xData.find("Results");
            }
            
            // Store the responses
            opt._status = status;
            
            $(xData.responseXML)
                .find("Results Result")
                    .clone()
                    .appendTo(opt._xDataResultsEle);
            
            // If the last item processed did not reach the end of the updates,
            // then call makeUpdates() again.
            if (opt._lastIndex < opt._totalUpdates) {
                
                makeUpdates();
            
            // ELse, we reached the end... resolve Deferred
            } else {
            
                // If user had defined a callback, then call it now
                if ($.isFunction(opt._completeFunc)) {
                    opt._completeFunc.call($, opt._xData, opt._status);
                }
                
                // Resolve deferred.
                dfd.resolveWith($, [opt._xData, opt._status]);
                
            }
            
            return;
            
        }
        
        // Loops through list of updates
        function makeUpdates() {
            
            var counter = 0,
                updXml  = '';
            
            // build update contract
            while ( counter < opt.batchSize && opt._lastIndex < opt._totalUpdates ) {
                
                counter++;
                opt._lastIndex++;
                
                updXml += opt.updates[opt._lastIndex];
                
            }
            
            opt.SPServicesOptions.updates = "<Batch OnError='Continue'>" + updXml + "</Batch>";
            
            // make call to SP
            $().SPServices(opt.SPServicesOptions);
            
        }
        
        makeUpdates();
        
    })
    .promise();
    
}//end: function: bulkUpdate()


Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>