Skip to content

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

@bennyszantar

Description

@bennyszantar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions