Verify if document exists
Posted: 26 Aug 2020
Hi all,
I use following script for the related items ( found in your blog https://spform.com/javascript-framework ... ctionality)
fd.updateDroppedDocuments($('.related-docs'), {
Customer: GetUrlKeyValue('ID')
});
//Add fields automatically to the uploaded documents
fd.updateDroppedDocuments($('.related-docs'), function(listItem) {
//get the values from the Form fields:
var cun = listItem.get_fieldValues().FileLeafRef;
var num = fd.field("Title").value();
var doc = fd.field("Document_x0020_Type").value();
var selected = fd.field("Measuring_x0020_Task").value();
var mst = '';
for (var i = 0; i < selected.length; i++) {
mst += fd.field('Measuring_x0020_Task').control()._el().find('input[type="checkbox"]').eq(i)[0].labels[0].innerHTML + '; ';
}
var Pg = fd.field("Main_x002d_Product_x002d_Group").value();
var Pr = fd.field("Product").value();
//set the values on uploaded document:
listItem.set_item('Title', cun);
listItem.set_item('AK_x002d_Number', num);
listItem.set_item('Document_x0020_Type', doc);
listItem.set_item('Measuring_x0020_Task', mst);
listItem.set_item('Main_x002d_Product_x002d_Group', Pg);
listItem.set_item('Product', Pr);
listItem.update();
//rename the uploaded document
//read the name of the file
var currentName = listItem.get_fieldValues().FileLeafRef;
//new name for the file:
var newName = fd.field("Title").value();
//file name with the current directory:
var newFileName = listItem.get_item('FileDirRef') + '/' + newName + "-" + currentName;
//finally, renaming the file after all the code:
listItem.get_file().moveTo(newFileName);
});
When I add the same file (Value=FileLeafRef) to the related items, the existing file should be replaced. Can you help me?
Best wishes
Tom
I use following script for the related items ( found in your blog https://spform.com/javascript-framework ... ctionality)
fd.updateDroppedDocuments($('.related-docs'), {
Customer: GetUrlKeyValue('ID')
});
//Add fields automatically to the uploaded documents
fd.updateDroppedDocuments($('.related-docs'), function(listItem) {
//get the values from the Form fields:
var cun = listItem.get_fieldValues().FileLeafRef;
var num = fd.field("Title").value();
var doc = fd.field("Document_x0020_Type").value();
var selected = fd.field("Measuring_x0020_Task").value();
var mst = '';
for (var i = 0; i < selected.length; i++) {
mst += fd.field('Measuring_x0020_Task').control()._el().find('input[type="checkbox"]').eq(i)[0].labels[0].innerHTML + '; ';
}
var Pg = fd.field("Main_x002d_Product_x002d_Group").value();
var Pr = fd.field("Product").value();
//set the values on uploaded document:
listItem.set_item('Title', cun);
listItem.set_item('AK_x002d_Number', num);
listItem.set_item('Document_x0020_Type', doc);
listItem.set_item('Measuring_x0020_Task', mst);
listItem.set_item('Main_x002d_Product_x002d_Group', Pg);
listItem.set_item('Product', Pr);
listItem.update();
//rename the uploaded document
//read the name of the file
var currentName = listItem.get_fieldValues().FileLeafRef;
//new name for the file:
var newName = fd.field("Title").value();
//file name with the current directory:
var newFileName = listItem.get_item('FileDirRef') + '/' + newName + "-" + currentName;
//finally, renaming the file after all the code:
listItem.get_file().moveTo(newFileName);
});
When I add the same file (Value=FileLeafRef) to the related items, the existing file should be replaced. Can you help me?
Best wishes
Tom