Code below works to draw a table using CEWP SPO. I need to add a button on every row in the same table that would move corresponding files from it's current location to another document library in the same SPO site. File names are retrieved using FileLeafRef.
The data is pulled using the Ajax GET type and move command would use POST type. Kindly assist to merge both functions to get the desired.
Current code
$(function(){
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('List_Name')/items?$top=10&$orderby=Created%20desc&$select=Reg,NBR,Date";
$.ajax({
url: requestUri,
type: "GET",
headers: {
"accept":"application/json; odata=verbose"
},
success: onSuccess,
});
function onSuccess(data) {
var objItems = data.d.results;
var tableContent = '<table id="Table"><tr><th>Reg</th><th>Num</th><th>Date</th></tr>';
for (var i = 0; i < objItems.length; i++) {
tableContent += '<tr>';
tableContent += '<td>' + objItems[i].Reg + '</td>';
tableContent += '<td>' + objItems[i].NBR + '</td>';
tableContent += '<td>' + moment(objItems[i].Date).format("DD-MM-YYYY") + '</td>';
tableContent += '</tr>';
}
$('#Grid').append(tableContent);
}
});
Move file code
function MoveFile(){
var oUrl = _spPageContextInfo.webAbsoluteUrl +"/_api/web/getfilebyserverrelativeurl('/Lib1/doc.docx')/moveto(newurl='/Lib2/doc.docx',flags=1)";
$.ajax({
url: oUrl,
type: "POST",
headers: {
"Accept": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(data){
console.log(data);
},
error: function(data){
console.log(data);
}
});
}