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