On file upload is the script below. Our intention is to rename the files on upload of course. This time, the new filename must contain the uploaded filename. We used the original script to rename a file but added this part to retrieve the original filename.
library.items.select("FileLeafRef", "FileRef").filter("Id eq " + itemIds[i]).get().then(function(items) {
currentName = items[0].FileLeafRef;
var extension = currentName.substring(currentName.lastIndexOf(".")+1);
var fname = currentName.substring(0, currentName.lastIndexOf('.'));
finalName = newfilename + ' ' + fname + ' ' + newDate + '.' + extension;
alert(currentName);
})
We get the uploaded file name and pull it apart as needed. Then we expect to move on to the actual renaming but we never get any of the global var's set in the above script for this section.
library.items.getById(itemIds[i]).inBatch(batch).update({
Title: currentName
}, "*", entityTypeFullName);
}
batch.execute().then(function(){
fd.control('Documents').refresh();
alert('Refreash Complete');
Full upload script in the
fd.spRendered(function() {
fd.control('Documents').$on('filesUploaded',
function(itemIds) {
var library = pnp.sp.web.lists.getByTitle('Project Documents');
library.getListItemEntityTypeFullName().then(function(entityTypeFullName){
var batch = pnp.sp.web.createBatch();
statusdate = fd.field('Status_x0020_Date').value;
var newDate = convertDate(statusdate);
for(var i = 0; i < itemIds.length; i++){
alert('Count = ' + i);
library.items.select("FileLeafRef", "FileRef").filter("Id eq " + itemIds[i]).get().then(function(items) {
currentName = items[0].FileLeafRef;
var extension = currentName.substring(currentName.lastIndexOf(".")+1);
var fname = currentName.substring(0, currentName.lastIndexOf('.'));
finalName = newfilename + ' ' + fname + ' ' + newDate + '.' + extension;
alert(currentName);
})
library.items.getById(itemIds[i]).inBatch(batch).update({
Title: currentName
}, "*", entityTypeFullName);
}
batch.execute().then(function(){
fd.control('Documents').refresh();
alert('Refreash Complete');
});
});
});
I'm sure it's simple, just need a push?