In SharePoint and using SPServices, I am trying to update the content of the files uploaded in the sub folders This is the image and also the file metatdata i want to update. The library structure looks like this:
List Name: Shared Documents
Folder #1 - Documents Subfolder #1 - Procurement File #1 - uploaded files File #2
So basically i want to update the requestID, filetype, etc
Can anyone help? Thanks!
Here is my code
var oldFolderName = "Procurement";
$().SPServices({
operation: "GetListItems",
async: false,
listName: 'Documents',
CAMLViewFields: "<ViewFields Properties='True' />",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></Where></Query>",
CAMLQueryOptions: "<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode('z:row').each(function () {
var existingFolderName = $(this).attr("ows_FileLeafRef").split(";#")[1];
if (existingFolderName == oldFolderName) {
var Folder_ID = $(this).attr("ows_ID");
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "Update",
listName: 'Documents',
valuepairs: [["Title", "Working"], ["requestID", "Working"]],
ID: Folder_ID,
completefunc: function (xData, Status) {
console.log("Folder Name Updated Successfully...");
}
});
}
});
}
});
But the code is only updating the Sub folder metadata (Procurement) not the list in the procurement folder.
No need to use SPService to loop folder firstly and then update file metadata, instead,use Rest API getfilebyserverrelativeurl to get file and update metadata like below:
For _api/Web/getfilebyserverrelativeurl:
the url value should be
/sites/sitename/Shared%20Documents/Procurement/filename in this case,
if it's a root site which no "sites" character in the site url, then change like this:
/Shared%20Documents/Procurement/filename