2

I want to make file attachments mandatory in a list. Every new element should have an attachment. Therefore I used a content editor webpart with following sourcecode:

<script type="text/javascript" language="javascript">
function PreSaveAction() {
            var elm = document.getElementById("idAttachmentsTable");
            if (elm == null || elm.rows.length == 0)
{
                document.getElementById("idAttachmentsRow").style.display='none';
alert("Please attach Documents");
return false ;
}
else { return true ;}
}
</script>

Unfortunately it doesn't work. If I replace the code with anything like abcdef the webpart doesn't appear at the new element form. Does someone has any ideas and suggestions? Thanks in advance.

Tobias

4

You can try by using Infopath. Please try steps given below:

  • On the List tab of the ribbon, Click Customize form enter image description here
  • To make the attachment field required, we will add a dummy textbox control that will contain the required rule. To do this, add a textbox control and place it before the attachment field enter image description here
  • Right click on the textbox control, hover on ‘Rules’ and click on Manage Rules. enter image description here
  • Create a rule for the textbox. Click on the ‘New’ rule button and click on Validation. Add a name to your rule. On the Condition window, Select the ‘Attachments’ field and on the condition, select ‘Is Blank’.

enter image description here

  • Create another rule to hide the textbox. Click on the ‘New’ rule button and click on Formatting. Tick on the checkbox ‘Hide this control’.

enter image description here

  • That’s it! We are done. Try to add an item to the list and try to not add an attachment. The save operation should fail. The infopath should raise an error indicating that a required attachment field is empty.
  • This way doesn't work but your idea is pretty good. It worked this way: I created the textfield like you said and made it mandatory. Then i added a rule, which writes the attachment-name into this field. After all i hid the field with a second rule. – Tobias Feb 6 '15 at 15:01
2

Instead of a list, why not use a library? They wouldn't be able to get started without a document, and a library still supports metadata fields. No code or other customizations would be needed.

  • One potential drawback is that with a library, you have to "attach" the file prior to ever seeing the form into which you'd supply the metadata. That could have a significant impact on usability - you are then pretty much obligated to provide supplemental instructions. In a list, you can easily build your instructions directly into the form using each field's Description attribute in List Settings. – Dan Henderson Apr 4 '17 at 15:42
  • Another is that this prevents you from having the option of making the attachment only required on particular content types. For example, suppose you have a "Requests" list where one content type is "Printing Services". You would want the attachment to be required for that content type, but not necessarily for others. That said, it is a simple solution that may work in some cases, so have a +1. – Dan Henderson Apr 4 '17 at 15:47
0

You can try doing the following to mandate the file attachment on a list(using infopath): 1. Add a text box control in the form (and hide in a section as we don't need this control to be shown) 2. Add a calculated value control under the file attachment and associate it with the above created text box control. 3. Now add a formatting rule on the calculated value control to hide when attachment is NOT blank. 4. Lastly, add an action rule on the SUBMIT button to set the value of the above text box control with the value such as "File attach is mandatory. Please attach" when the condition file attachment is blank. And further running of any rules if the condition is true.

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.