Get a count of attachments

rss

Posted by Dan_C - Dec 18 ’14 at 02:32

Hi Dmitry,

Any suggestion on how I can get a count of the attachments added so far?  I have a requirement for a minimum number of attachments.

Thanks!

  • Dan_C
    Member
    Member for: 5 years 15 days
    #1 by Dan_C Dec 18 ’14 at 02:49

    The other option I'm considering is using the Related Items feature as each attachment relates to an item.

    http://formsdesigner.blogspot.com/2013/08/how-to-create-forms-with-related-items.html

    I was reading this article and I just want to confirm with you...

    Can I pass the current item's id into a field in another list (child)... and thus cause the new item to be related to the parent?

    The related items section on the parent form would always be empty until a new item was created which linked the two via a field in the child called Parent_ID with the parent item's ID field.

    Hopefully I'm explaining that in a clear way.  I'd want to add related items and associate them with the current parent item by default.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 22 days
    #2 by Dmitry Kozlov Dec 19 ’14 at 10:22

    [#1]: Hi,

    Yes, you can use the Related items control. In the post you've mentioned above, I described how to prepopulate a lookup field in a child form via JavaScipt. Please, note that you cannot use related items in a new form because the parent item is not created yet.

    You can still use the attachments field and I can provide you with code that checks whether the user has added a particular number of attachments.

  • Dan_C
    Member
    Member for: 5 years 15 days
    #3 by Dan_C Dec 19 ’14 at 12:00

    [#2]: Yes - I came across that issue.

    I think it's better for my scenario that I get a count of the number of attachments.  What do you suggest?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 22 days
    #4 by Dmitry Kozlov Dec 22 ’14 at 08:02

    [#3]: Please, place the following code into JS-editor.

    fd.onsubmit(function() {
    	if ($('#idAttachmentsTable tr').length < 2) {
    		alert('Please, add at least two attachments');
    		return false;
    	}
    	
    	return true;
    });
    

    It checks whether the current user has added at least two attachments before the submission.

  • Dan_C
    Member
    Member for: 5 years 15 days
    #5 by Dan_C Dec 22 ’14 at 07:12

    [#4]: Hi Dmitry,

    Works great.  Thank you.

    How about getting a count of the number of related items for a similar purpose?  I know this question will come up as I add related items to my form.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 22 days
    #6 by Dmitry Kozlov Dec 23 ’14 at 12:47

    [#5]: Hi,

    It depends on the rendering mode of the related items. Please, specify which one do you use: server or client side?

  • Dan_C
    Member
    Member for: 5 years 15 days
    #7 by Dan_C Dec 23 ’14 at 11:03

    [#6]: Not sure yet.  I am just adding it in this morning.  Could you mention both ways?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 22 days
    #8 by Dmitry Kozlov Dec 24 ’14 at 04:10

    [#7]: Please, assign a CSS class to the related items control in Forms Designer e.g. related-items. Next, insert the following code into JS-editor:

    fd.onsubmit(function() {
    	if ($('.related-items .ms-listviewtable > tbody > tr').length < 2) {
    		alert('Please, add at least two attachments');
    		return false;
    	}
    	
    	return true;
    });
    
Displaying 1 to 8 of 8 messages