Forum
Merhaba,
Bir sorum olacakti, ben REST API kollanarak bir listeye eklimek ve guncellemek istedim surekli bir hata veriyor.
Hata:
Eger queryUrlupdate updateApplicationToList function ni " var queryUrlupdate = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('BizSrv')/items('" + id + "')";"
degistirip " var queryUrlupdate = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('BizSrv')/items";"
yaptigimda bu hatayi veriyor :
{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The type SP.ListItemEntityCollection does not support HTTP PATCH method."}}}
2. Eger queryUrlupdate updateApplicationToList function ni boyle olsa " var queryUrlupdate = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('BizSrv')/items('" + id + "')";"
Bu hatayi veriyor:
jquery-1.11.0.min.js:4 POST https://sitecllname/site/_api/web/lists/getbytitle ('BizSrv')/items('') 400 (Bad Request)
send @ jquery-1.11.0.min.js:4
ajax @ jquery-1.11.0.min.js:4
updateApplicationToList @ BizSrvOperations.js:232
insertOrUpdateApplication @ BizSrvOperations.js:7
onclick @ BizSrv.aspx:648
BizSrvOperations.js:253 {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Input string was not in a correct format."}}}
function insertOrUpdateApplication(){
var mode = getParameterByName("Mode");
if(mode == 'add'){
addApplicationToList();
}
else{
updateApplicationToList();
}
}
function addApplicationToList(){
if(validation()){
//$('#LoadingIcon').show();
debugger
var SubmitProperties = {
'__metadata': { 'type': 'SP.Data.ApplicationCatalogueListItem' },
};
console.log(SubmitProperties);
var requestHeaders = { 'Accept': 'application/json;odata=verbose', 'X-RequestDigest': $('#__REQUESTDIGEST').val() };
var queryUrladd = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('BizSrv')/items";
console.log("queryUrladd", 'queryUrladd');
$.ajax({
url: queryUrladd,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(SubmitProperties),
async: false,
headers: requestHeaders,
success: function(data) {
swal({
title: "Application Catalogue: ",
text: "Thank you.. Your application submitted successfully !!!",
type: "success",
confirmButtonColor: "#74CA65",
confirmButtonText: "OK",
closeOnConfirm: false
},
function(){
window.location = _spPageContextInfo.webAbsoluteUrl + '/Pages/BizSrvDashboard.aspx';}
);
},
error: function(errorMsg) {
$('#LoadingIcon').hide();
console.log(errorMsg.responseText);
if(errorMsg.responseText.includes("UnauthorizedAccessException")){
swal("Access denied!\n Project Name already exists", "You do not have permission to perform this action.", "error");
}
}
});
}
}
function updateApplicationToList(){
if(validation()){
//$('#LoadingIcon').show();
var id = $("#applicationID").val();
var SubmitProperties = {
'__metadata': { 'type': 'SP.Data.ApplicationCatalogueListItem' },
};
var requestHeaders = {
'Accept': 'application/json;odata=verbose',
'X-RequestDigest': $('#__REQUESTDIGEST').val(),
'X-HTTP-Method': 'MERGE',
'If-Match': '*'
};
var queryUrlupdate = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('BizSrv')/items('" + id + "')";
console.log("queryUrlupdate",'queryUrlupdate');
$.ajax({
url: queryUrlupdate,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(SubmitProperties),
async: false,
headers: requestHeaders,
success: function(data) {
swal({
title: "Application Catalogue: ",
text: "Thank you.. Your application submitted successfully !!!",
type: "success",
confirmButtonColor: "#74CA65",
confirmButtonText: "OK",
closeOnConfirm: false
},
function(){
window.location = _spPageContextInfo.webAbsoluteUrl + '/Pages/BizSrvDashboard.aspx';}
);
},
error: function(errorMsg) {
console.log(errorMsg.responseText);
}
});
}
}
Simdiden tesekkur ederim, sagolun
Ben hatayi boldum, yavas yavas debug ettim Fiddler ve Chrome ile, belkide arkadaslara yarari olur:
function insertOrUpdateApplication(){
var mode = getParameterByName("Mode");
var webUrl = _spPageContextInfo.webAbsoluteUrl;
//console.log(listName);
if(mode == 'add'){
addApplicationToList();
}
else{
updateApplicationToList();
}
}
function addApplicationToList(){
//console.log(listName);
//console.log(webUrl);
if(validation()){
//$('#LoadingIcon').show();
var listName = "listname degistir";
//var listItemEntityTypeFullName=getListType(webUrl,listName);
var SubmitProperties = {
'__metadata': { 'type': 'SP.Data.BizServiceCatalogueListItem' },
ve
var requestHeaders = { 'Accept': 'application/json;odata=verbose', 'X-RequestDigest': $('#__REQUESTDIGEST').val() };
var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+ listName +"')/items";
Hata 3 yerdemis:
1. '__metadata': { 'type': 'SP.Data.BizServiceCatalogueListItem' }, i ben kafadan uydurmusum onu
de bulunurmus,
2. var listName = "listname"; i addApplicationToList function icine ekledim hep undefined verdi,,
3. var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+ listName +"')/items"; busekilde yazdim ve ekelencek kayitlari birer bir ekledim
var SubmitProperties = {
'__metadata': { 'type': 'SP.Data.BizServiceCatalogueListItem' },
'Title': $('#serviceName').val(),
---- baska fieldler
---- baska fieldler
---- baska fieldler
};
var requestHeaders = { 'Accept': 'application/json;odata=verbose', 'X-RequestDigest': $('#__REQUESTDIGEST').val() };
var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+ listName +"')/items";
console.log(queryUrl);
$.ajax({
url: queryUrl,
type: "POST",
//data: SubmitProperties,
contentType: "application/json;odata=verbose",
data: JSON.stringify(SubmitProperties),
async: false,
headers: requestHeaders,
success: function(data) {
swal({
title: "listname: ",
text: "Thank you.. Your application submitted successfully !!!",
type: "success",
confirmButtonColor: "#74CA65",
confirmButtonText: "OK",
closeOnConfirm: false
},
function(){
window.location = _spPageContextInfo.webAbsoluteUrl + '/Pages/Dashboard.aspx';}
);
},
Eger yardim lazim olsa yazarsiniz