Я написал код для пунктов списка заезда / выезда. Он отлично работает с администраторами, но любой другой уровень разрешений имеет проблемы, 401 несанкционированная ошибка с UpdateListItems на "_vti_bin / lists.asmx" для сайта. Я подтвердил, что пользователи могут просматривать веб-сервис "_vti_bin / lists.asmx".
//declare variables used for check-in/check-out.
var varName;
var varChecked;
var varID
var varQueryStringVals;
//Check who has checked out the item
function getCheckOutPerson (){
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Communications Services Request Form",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>" + varID + "</Value></Eq></Where></Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
varChecked = $(this).attr("ows_CheckedOutTo");
});
}
});
};
$(document).ready(function() {
//Check-in if edits cancelled
$("#cancelBtn").click(function(){
//Check in edited item.
if (varName == varChecked){
$().SPServices({
operation: "UpdateListItems",
async: false,
debug: true,
listName: "Communications Services Request Form",
ID: varID,
valuepairs: [["CheckedOutTo", ""]],
completefunc: function(xData, Status) {}
});
};
});
//get current user
varName = $().SPServices.SPGetCurrentUser({
fieldName: "Title",
debug: false
});
//get current list item ID
varQueryStringVals = $().SPServices.SPGetQueryString();
varID = varQueryStringVals["ID"];
//get checked out name
getCheckOutPerson();
// item checked in or checked out by current user?
if (varChecked == undefined || varName == varChecked){
//check out item
$().SPServices({
operation: "UpdateListItems",
async: false,
debug: true,
listName: "Communications Services Request Form",
ID: varID,
valuepairs: [["CheckedOutTo", varName]],
completefunc: function(xData, Status) {
}
});
};
//checked out message
if (varChecked != undefined && varName != varChecked) {
alert ("You cannot edit this item. It is check out by " + varChecked +".");
history.back();
};
//Display 'checked out to' in dispitem.aspx
getCheckOutPerson();
if ($('.CheckedOut').text('')) {
$('.CheckedOut').append(varChecked);
}
});
function PreSaveAction() {
if (varName != varChecked){
alert ("You cannot make changes to this item. It it checked out to " + varChecked);
return false;
};
//Check in edited item.
$().SPServices({
operation: "UpdateListItems",
async: false,
debug: true,
listName: "Communications Services Request Form",
ID: varID,
valuepairs: [["CheckedOutTo", ""]],
completefunc: function(xData, Status) {}
});
return true;
};