1

I have a custom list in SP13 with a choice column containing 'Yes', 'No', and 'NA' drop down values. If the column value is marked 'Yes', I want to require the user to attach a related file to the record.

OOTB SP13 Choice type column is named Commercial Bus. Drop-Down Menu choices are Yes, No, NA. "Yes" requires a Commercial Bus Request Form be attached before the new (or edited) form can be saved.

I've seen one JQuery solution on here but from the post I an unable understand the JS syntax required for the script to recognize the column and option combination as a pre-save event. Could this be handled with column validation or is it strictly a JS solution. Any help is creating a formula or JS solution that I can place into a script editor box on the list New Form and Edit Form aspx is greatly appreciated.

-Joe

0

You need to use JavaScript.

  1. Use F12 to get the id of "Commercial Bus" element

    enter image description here

  2. Edit NewForm.aspx and EditForm.aspx, add a Script Editor web part and enter the following script to the web part.

Note: change "Commercial_x0020_Bus_bc09f2d5-45a7-4255-8164-9f12207bf74f_$DropDownChoice" to your's element id found in step 1.

<script type="text/javascript" language="javascript">
function PreSaveAction() {
    var CommercialBusValue= document.getElementById("Commercial_x0020_Bus_bc09f2d5-45a7-4255-8164-9f12207bf74f_$DropDownChoice").value;
    var atch = document.getElementById("idAttachmentsTable");
    if(CommercialBusValue == "Yes"){
        if (atch == null || atch.rows.length == 0)
        {
            alert("Documents attachment is required");
            return false ;
        }else {
            return true;
        }
    }else{
        return true;
    }
}
</script>
  1. Save the page.

After that, the item must has attachment(s) if user selects "yes". Otherwsise, he will get an alert and the item will not be saved.

enter image description here

  • Perfect! Thank you very much for providing this. If I may ask a follow up question: How do I write in multiple elements – Joe Jan 2 at 15:09
  • What do you mean by "write in multiple elements"? – JoannaW_MSFT Jan 3 at 1:32

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.