spscript
spscript copied to clipboard
Some SPScript methods doesn't work with sp-rest-proxy (easy fix)
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.
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