Get a count of attachments

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Dan_C
Posts: 63
Joined: Tue Dec 02, 2014

18 Dec 2014

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
Posts: 63
Joined: Tue Dec 02, 2014

18 Dec 2014

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

http://spform.com/office-365/crea ... office-365

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.

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

19 Dec 2014

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
Posts: 63
Joined: Tue Dec 02, 2014

19 Dec 2014

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?

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

22 Dec 2014

Please, place the following code into JS-editor.

Code: Select all

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
Posts: 63
Joined: Tue Dec 02, 2014

22 Dec 2014

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.

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

23 Dec 2014

Hi,

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

Dan_C
Posts: 63
Joined: Tue Dec 02, 2014

23 Dec 2014

Not sure yet. I am just adding it in this morning. Could you mention both ways?

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

24 Dec 2014

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:

Code: Select all

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

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

06 Oct 2017

Sorry for bringing this old tread up... It is logical to add here than start a new one.

I need to restrict the number of related items: not more than 25, and not permit to save more (it's a registration form)... is there a way to do that?

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests