0

I have a regular list, and the NewForm.aspx page is opened as a modal dialog.
When a user wants to add a new item to that list and adds an attachment to that list, I'd like to be able to change the name of that attachment before the new item gets saved.

So for example: a user adds an attachment to a new list item, and that attachment is called "attachment.docx". The moment the user clicks on the "Save" button to save the new list item to the list, I'd like to change the name of the attachment to "attachment blablabla.docx". When a user then opens that item, the user will see the new name of the attachment.

How can I achieve this? I want to do this with only JavaScript. So far I found several sites mentioning "function PreSaveAction()" but I can't get it to work, it doesn't do an alert or anything.

Any help would be greatly appreciated!

0

You cannot change it before the item is saved, first; you are not allowed to change the type=file input value, since the files points to your file system.

And the actual attachments are not upload before the item is saved. Hence you cannot change them before the item is created. The attachments are stored in the list to the item, under the folder Attachment/{ID of item}

What you could do, is to take control over the launch of the dialog. And on the callback query the list for last ID added, then fetch the folder if any, and if a folder, check the files, then check if the file name needs to be changed and update it.

Maybe other ways, but just my first thought.

  • Thanks, you're right. I can't change the attachment before the item is changed. – Magali Nov 26 '14 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.