Good Afternoon,
I have followed this link to update MetaData on File Upload documents.
One of the field is DOC_Department and is a Taxonomy field (Managed Metadata). I have been googling to find a way to update the value in this Taxonomy field.
Here is my codes.
fd.control('Documents').$on('filesUploaded', function(itemIds) {
SetFilename(itemIds, 'TestDocuments')
});
function SetFilename(itemIds, v) {
var docLibraryTitle = 'Test Documents';
var deptValue =
{
"Label": 'Finance',
"TermGuid": '99999999-9999-9999-99999999999999999',
"WssId": 20
};
pnp.sp.web.siteUsers.getByLoginName(fd.field('EmployeePerson').value.Key).get()
.then(function(result) {
console.log('FileUpload result ', result);
console.log('FileUpload resultId ', result.Id);
var library = pnp.sp.web.lists.getByTitle(docLibraryTitle);
//go through each uploaded Item Id and set field values
library.getListItemEntityTypeFullName().then(function(entityTypeFullName){
var batch = pnp.sp.web.createBatch();
for(var i = 0; i < itemIds.length; i++){
console.log("itemIds ");
console.log(itemIds);
//specify which fields to update and how - FileLeafRef: fd.field('Title').value
console.log('library.items ', library.items.getById(itemIds[i]));
library.items.getById(itemIds[i]).inBatch(batch).update({
FileLeafRef: v + '_' + new Date().toISOString().split('.')[0].replace(/[^\d]/gi,'') + '_(' + i + ')',
DOC_x0020_OwnerId: result.Id,
DOC_x0020_Department: deptValue,
DOC_x0020_Category: v
}, "*", entityTypeFullName);
} // for
batch.execute().then(function(){
fd.control(v).refresh();
});
}); // library
}); // pnp
}
All the fields updated successfully except for the Department Taxonomy field. There's no error showing in the console log so I don't think it's the codes. I found a Github link that mentioned it may be a bug but I am not sure how to fix it.
How can I update Taxonomy field through batch update?
Thank you so much in advance for your help with this!