Verify if document exists

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
TWendt
Posts: 109
Joined: Mon Sep 08, 2014

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

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

27 Aug 2020

Hello Tom,

You can specify the kind of move operation using SP.MoveOperations like this:

Code: Select all

fd.updateDroppedDocuments($('.related-docs'), function(listItem) {
console.log(listItem);
    //new name for the file:
    var newName = "newName.pdf";
 
    //file name with the current directory:
    var newFileName = listItem.get_item('FileDirRef') + '/' + newName;
 
    //finally, renaming the file after all the code:
    listItem.get_file().moveTo(newFileName, SP.MoveOperations.overwrite);
});

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests