Skip to main content

I am creating a expense form and I am trying to validate the number of attachments on my form. 

First I tried to follow the solution on in this blog post (Attachement in repeating section ) to add attachments to each row in my repeating table. However, this HTML does not seem to actually work. It looks nice on the form but it does not actually do anything with the attachments. And even if it did, I could not find a way to make the field required when the user selects "yes" on the receipts attached field.

I also looked at this post (attachments custom validation  )but I do not know how to write JS so this was totally over my head. 

I have created a calculated field that adds up the number of times "Yes" is selected on the receipts attached field and ideally I would be able to use that field in the minimum attachments required field on the attachments control, however that does not seem to work either. 

A less than idea, but workable, solution would be for me to make the minimum attachments required equal 1 if yes is selected at all, but I have tried a few formulas for that and can not seem to make it work.

Any advice?

203456_pastedImage_18.png

203457_pastedImage_19.png

203458_pastedImage_20.png

203462_pastedImage_21.png

203463_pastedImage_22.png

Are you getting the correct number at all for your "TotalNumReceipts" value? As in, are those summing correctly? Also, when you say it "doesn't work<" do you mean they're able to submit even without the correct number of attachments (ex too few) or that they're unable to submit even if they have the correct number of attachments?


Yep, that field is working correctly. And yes, when I saw it doesn't work, they are able to submit no matter how many attachments they add. 


Ok, so when I go to do this, I notice in the "Minimum Attachments" field for the attachments control, there's no "Named Controls" available, it's only Item Properties. So since you have your TotalNumReceipts control connected to a column of the same name (it appears), the problem is that the column value isn't updated until save. That's why, typically, for dynamic form stuff you typically use the "Named Controls" because those update when the control updates. SO, in short, your problem is that you're checking against a value of 0. 


ah that makes sense... Is there a work around that you know of?


unfortunatelly there is no other way then use javascript.

have look at these other use cases of my function. maybe some of will make it more clear how to use it.

https://community.nintex.com/search.jspa?q=getnumberofattachments 

basically, it's quite easy. copy & paste script into forms settings. you need to change anything in it.

the configure some class to a attachment control. in function call pass this class as an input paramater.

that's all you need to do.


Yay! Thank you, I actually got it to validate to make sure there was at least one receipt when receipts attached is yes. Is it possible to make sure that there are the exact amount attached? For example if there are three rows with receipts attached Yes selected, can I validate to make sure there are at least 3 items attached?


I wanted to add my solution:

I used Marian's JS code to make this work

function GetNumberOfAttachments(attCtrlClassName){  
    return NWF.FormFiller.Attachments.GetAttachedFilesCount(NWF.FormFiller.Functions.GetFillerDivObjectForControl(NWF$("#"+NWF$("." + attCtrlClassName + " .nf-attachmentsRow")a0].id)).data('controlid'))
 } 

Step 1) add the JS code to the custom JS section in the main form settings

203472_pastedImage_1.png

Step 2) Change the css class in the attachment control. Name it the same thing that you called in the second part of the function GetNumberOfAttachments(attCtrlClassName) so my css class name is "attCtrlClassName" (without the quotes)

203473_pastedImage_7.png

step 3) Add a validation rule on the attachments control. I have a calculated value and I wanted the user to have to attach a number of documents that was greater than or equal to the number in my calculated value. Therefore if the calculated value field totalnumberofreceipts is equal to or greater than 1 (meaning some receipts are required) and totalnumberofreceipts is greater than the total number of attachments (GetNumberOfAttachments(attCtrlClassName)) then the attachment control is invalid and the form can not be submitted. This means that the user must attach at least as many receipts as they have expenses before they can submit their expense reimbursement request. 

203474_pastedImage_8.png the full formula I used is greaterThanOrEqual(TotalNumReceipts,1)&&greaterThan(TotalNumReceipts,GetNumberOfAttachments("attCtrlClassName"))


Great solution...This works for one of my attachment controls but I have 5 separate attachment controls.

My form has one of these per 'Driver' named. If driver1 is not Null then the attachment control must contain at least 2 attachments, 1 for the license and another for a certificate. The problem I have using this solution is that once driver2 has uploaded 2 attachments the driver3 attachment control does not require any attachments and the from will submit without them. Any idea's?

Thanks

Nick


Reply