spscript icon indicating copy to clipboard operation
spscript copied to clipboard

Some SPScript methods doesn't work with sp-rest-proxy (easy fix)

Open bennyszantar opened this issue 5 years ago • 1 comments

Hi,

I've noticed that update/delete list item doesn't work when using sp-rest-proxy (local development with data from SP server), because in methods updateItem and deleteItem you use URL returned from list metadata, not that one used in createContext method.

This is my patch that I use, Im simply building the URL with _this.baseUrl: var updateUri = _this.baseUrl+"/items("+itemId+")";

List.prototype.updateItem = function (itemId, updates, digest) {

    var _this = this;
    return this._dao.auth.ensureRequestDigest(digest).then(function (digest) {
        return _this.getItemById(itemId).then(function (item) {
            //decorate the item with the 'type' metadata
            updates = Object.assign({}, {
                __metadata: {
                    type: item["__metadata"].type,
                },
            }, updates);
            var updateUri = _this.baseUrl+"/items("+itemId+")";

            var customOptions = {
                headers: utils.headers.getUpdateHeaders(digest, item["__metadata"].etag),
            };
            return _this._dao.post(updateUri, updates, customOptions);
        });
    });
};

With this change, update/delete works perfectly in local proxed and server environment.

bennyszantar avatar Apr 05 '19 08:04 bennyszantar

Hey thank you! I'm planning on finally getting back into SPScript to make some updates so I'll make sure to pull this in

DroopyTersen avatar Apr 15 '20 03:04 DroopyTersen