Get a count of attachments
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_CMemberMember for: 7 years 8 months 21 days
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 KozlovAdminMember for: 8 years 10 months 26 days
[#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_CMemberMember for: 7 years 8 months 21 days
[#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 KozlovAdminMember for: 8 years 10 months 26 days
[#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_CMemberMember for: 7 years 8 months 21 days
[#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 KozlovAdminMember for: 8 years 10 months 26 days
[#5]: Hi,
It depends on the rendering mode of the related items. Please, specify which one do you use: server or client side?
-
Dan_CMemberMember for: 7 years 8 months 21 days
[#6]: Not sure yet. I am just adding it in this morning. Could you mention both ways?
-
Dmitry KozlovAdminMember for: 8 years 10 months 26 days
[#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; });