Related documents | Extending the original file name
Posted: 30 Oct 2018
Hi all,
again I have some challenges that I am unable to solve.
I am using related documents to attach files to a form. That is working fine. But I want to change the name of the document that the user has uploaded.
So that the different name (before uploading and after) does not confuse the user, I want to keep his name and extend it.
Therefore, I want to write the original name in the column "Title" and add the form's ID to the original name in the field "Name". Otherwise I am have a problem if someone wants to attach a file with the same name to form ID 1 and ID 2 as the name is not unique anymore. Adding the form's ID would prevent that.
Example:
User uploads the file "Testfile" within the form ID 1.
After the upload, I want the "Title" to be "Testfile" and the name of the file to be "Testfile-1".
As I couldn't get the filename I used the path and wanted to extract the name.
fd.updateDroppedDocuments($('.attachies'), function(listItem) {
var testvar = listItem.get_file(); //getting the path
var lengthie = testvar.length;
var end = lengthie - 4; //getting rid of the file format
var output = testvar.substring(10,end); //extract the filename without file format and library name
listItem.set_item('Title', output);
listItem.update();
});
As I couldn't even get the file name and fill "Title" I haven't tried yet to change the actual file's name. Shouldn't be such a big problem as I have found one of your instructions to do so. But before editing the file's name I need to know it.
When I am using the above mentioned code the field "Title" is blank after uploading. However, if I try to write the entire path into "Title", it works. So the error has to be "length" or "substring".
Thank you very much in advance for your support!
again I have some challenges that I am unable to solve.
I am using related documents to attach files to a form. That is working fine. But I want to change the name of the document that the user has uploaded.
So that the different name (before uploading and after) does not confuse the user, I want to keep his name and extend it.
Therefore, I want to write the original name in the column "Title" and add the form's ID to the original name in the field "Name". Otherwise I am have a problem if someone wants to attach a file with the same name to form ID 1 and ID 2 as the name is not unique anymore. Adding the form's ID would prevent that.
Example:
User uploads the file "Testfile" within the form ID 1.
After the upload, I want the "Title" to be "Testfile" and the name of the file to be "Testfile-1".
As I couldn't get the filename I used the path and wanted to extract the name.
fd.updateDroppedDocuments($('.attachies'), function(listItem) {
var testvar = listItem.get_file(); //getting the path
var lengthie = testvar.length;
var end = lengthie - 4; //getting rid of the file format
var output = testvar.substring(10,end); //extract the filename without file format and library name
listItem.set_item('Title', output);
listItem.update();
});
As I couldn't even get the file name and fill "Title" I haven't tried yet to change the actual file's name. Shouldn't be such a big problem as I have found one of your instructions to do so. But before editing the file's name I need to know it.
When I am using the above mentioned code the field "Title" is blank after uploading. However, if I try to write the entire path into "Title", it works. So the error has to be "length" or "substring".
Thank you very much in advance for your support!