How can I find the no of rows in the uploaded excel file using aui script?
Please find the below ajax call.
I need to find the number of rows in excel sheet here.
function uploadFile(){
event.preventDefault();
A.io.request('${fileUploadCSV}', {
method: 'post',
form: {
id: '<portlet:namespace />uploadForm',
upload: true,
},
on: {
complete : function(e){
console.log("complete");
}
}
});
Related
I am new to Sharepoint and using 2013 classic version. I have created a website and in it, it has list with items. So, I need to trace the number of clicks of each item individually. My code is not working for tracing the number of clicks as the count gets stopped with 1 and doesn't increment then for individual item. But it counts overall clicks of all items in that list. I'm stuck with this for two weeks. Please help me and Many many thanks in advance.
function Getprevcount(linkname) {
var resturl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('abc')/items?$top=1000";
$.ajax({
url: resturl,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var lnt = data.d.results.length;
for (var i = 0; i < lnt; i++) {
if (data.d.results[i].Title == linkname) {
prevcount = data.d.results[i].Count;
}
}
},
error: function (data) {
console.log(data.responseJSON.error);
}
});
}
function Updatecount(updatlink) {
var resturl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('abc')/items?$select=Title&$filter=Name";
//alert(resturl);
prevcount = prevcount + 1;
//alert(prevcount);
$.ajax({
url: resturl,
method: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-HTTPS-Method": "MERGE"
},
data: "{__metadata:{'type':'SP.Data.TestcounterListItem'},Count:'1'}",
async: false, success: function (data) {
alert("I'm in Update Count Section");
console.log(prevcount);
},
error: function (data) {
console.log(data.responseJSON.error);
}
});
}
Look in the update function the line below it always update with the number you can use prevcount there to update the number.
data: "{__metadata:{'type':'SP.Data.TestcounterListItem'},Count:'1'}",
Need to modify the line below with prevcount variable:
data: "{__metadata:{'type':'SP.Data.TestcounterListItem'},Count: prevcount}",
Make sure the there is a field named "Count" in the Testcounter List.
I upload a file to sharepoint and trying to update its metadata, but I always get error 400 in last step.
As far as I understand, sharepoint only handles lists and items. A "folder" is a list and both metadata and files inside are items. And a "file" is a list and its metadata are items.
Documentation about updating metadata say about to make a POST request to:
https: // {site_url} / _api / web / lists / GetByTitle ('{list_title}') / items ({item_id})
Updating files must be done by PUT method (not MERGE allowed), but updating metadata must be done specifically by MERGE method. I have tried both, and both failed.
This is my current updating metadata request, but I'm continuing getting an error 400.
var data = {
"__metadata": {
"type":type
},
"Description":"lorem ipsum"
};
var headerToken = {
headers: {
'Authorization':'Bearer ' + token
, 'X-HTTP-Method':'MERGE'
, 'Accept':'application/json;odata=verbose'
, 'Content-Type':'application/json;odata=verbose'
, 'Content-Length':JSON.stringify(data).length
, 'If-Match': etag
, 'X-RequestDigest': digest
}
};
try {
var response = await axios.post(
'https://{site_url}/_api/web/lists/GetByTitle("'+MY_FOLDER+'")/items('+id+')'
, JSON.stringify(data)
, headerToken
);
return response;
}
type, etag and id are get from uploading file response and digest is get from a request to contextinfo endpoint. MY_FOLDER is a test library and at this moment is a constant.
You need to use single quotes in getbytitle.
"https://{site_url}/_api/web/lists/GetByTitle('"+MY_FOLDER+"')/items("+id+")"
Updated:
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
UpdateFolder()
function UpdateFolder(){
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Doc')/items(30)",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
},
data: "{__metadata:{'type':'SP.Data.DocItem'},test:'test'}",
/*where Title is column name and add your desired new data*/
success: function(data) {
console.log(data);
},
error: function(error) {
alert(JSON.stringify(error));
}
});
}
})
</script>
I am using an old SharePoint 2010 product.
Inside my site, I created a Status list which looks like this:
I found some Web Service API method which allows me to update some records like UpdateListItems() or UpdateList()
Can you please tell me how to build an update request to update the Status field based on the CaseNumber# field?
We can use listdata.svc to update list item based on the casenumber field. The following example code for your reference, modify the variables and add the code into a content editor web part, click the button to update list item.
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function updateListItem() {
var siteUrl="http://sp2010";
var listName="StatusList";
var caseNumber="456798";
var itemProperties={
'Status': 'Approval'
};
$.ajax({
url: siteUrl + "/_vti_bin/listdata.svc/"+listName+"?$filter=CaseNumber eq '"+caseNumber+"'",
type: "GET",
headers: {
"Accept": "application/json;odata=verbose",
},
success: function (data) {
var item=data.d.results[0];
$.ajax({
type: 'POST',
url: item.__metadata.uri,
contentType: 'application/json',
processData: false,
headers: {
"Accept": "application/json;odata=verbose",
"X-HTTP-Method": "MERGE",
"If-Match": item.__metadata.etag
},
data: Sys.Serialization.JavaScriptSerializer.serialize(itemProperties),
success: function (data) {
alert("succeeded.");
},
error: function (data) {
alert(JSON.stringify(data));
}
});
},
error: function (err) {
console.log(JSON.stringify(err));
}
});
}
</script>
<input type="button" value="update list item" onclick="updateListItem()"/>
i have a webpage that gets data from a local database. i can retrieve the data to be displayed but for some reason a certain value (value of '#item_name') does not display. it's supposed to be the text inside a select dropdown with an id of item_name. am i missing something? here is my code:
$.ajax({
url: '/get_items',
method: 'POST',
data: { item_id: item_id },
success: function (response) {
alert(JSON.stringify(response.result[0].name));
$('#hidden_item_item_id').val(response.result[0].id);
$('#item_name').val(response.result[0].name);
$('#item_remarks').val(response.result[0].remarks);
$('#updateItemsModal').modal('show');
}
});
Try this,
$('#item_name').append($("<option />").val(response.result[0].name).text(response.result[0].name));
Hope this helps!
You don't need to do JSON.stringify, just add dataType : 'json' in ajax request.
$.ajax({
url: '/get_items',
method: 'POST',
data: { item_id: item_id },
dataType: 'json',
success: function (response) {
alert(response.result[0].name);
$('#hidden_item_item_id').val(response.result[0].id);
$('#item_name').val(response.result[0].name);
$('#item_remarks').val(response.result[0].remarks);
$('#updateItemsModal').modal('show');
}
});
Please try
I have several lists in SharePoint, and each list has a number of views
How can I get view list items with value in SharePoint using REST API?
Can I get this data through CSOM?
When I use this method, I have this output :
http://win-lfl4bgulf29/_api/lists/getbytitle('EvertList')/views
But I'm looking for that
You can use the Endpoint like below to view list item data:
_spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbyTitle('EvertList')/items"
Ajax call like this:
$.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbyTitle('Cars')/items",
type: "GET",
contentType: "application/json;odata=verbose",
headers: {
"Accept": "application/json;odata=verbose"
},
success: function (data) {
console.log(data.d.results);
},
error: function (data) {
alert("Error");
}
});
Responsed Json in Console: