locked
How to set attachment as required in a Task list with multiple content types and not all of them RRS feed

  • Question

  • Greetings,


    I tried using the code below:

    "

     <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>

    "

    And it works perfectly if i put the code in a content editor webpart at the edit predetermined form, but it makes the attachment as required for all content types.

    I can see the content type ID in SP Designer but i need to customize some of them and not all, like predetermined form has to be "Not required" and some of the content type forms as "required".


    For example, i have the following content types in my tasks list called "Workflow Tasks".

    Tarea: Attachment not required.

    Viajes 1: Attachment required.

    Viajes 2: Attachment required

    Viajes 3: Attachment not required.


    I hope i get any help, thanks!

    Regards,

    Luis.

    Monday, January 28, 2019 4:32 PM

All replies

  • In your code, you can check the URL of the page you're on to determine the content type.

    var x = window.location.href will create a variable set to the URL.

    Your URL on your form will have something like ContentType= as a query string. Check the resulting variable for the substring of your content type ID. Create an if statement for those content types and make required when applicable.


    Please remember to mark as answer if you found this to be helpful. Andy Wessendorf

    Monday, January 28, 2019 5:52 PM
  • Hello,

    Thanks for the answer.

    Do i have to put your code inside the one i have?

    How do i retrieve the result of that variable "x"?

    Sorry, i'm very new with using code into sharepoint.

    I tried looking at the forms url via browser but it shows only the Item ID with a source query.

    Can you explain me with more details please.

    Thank you so much.

    Monday, January 28, 2019 9:10 PM