Make attachments required on condition


Badge +9

I'm implementing an expense claim. And the users are required to attach a receipt except if they are only claiming mileage. How do I create a condition on the attachments to be required if they select yes on a "yes/no - Mileage Only" field.

I tried to put a rule on the attachments to make it disabled if the user selects mileage only=yes. But how do i make it required to complete if mileage only=No?!

I found earlier an article here that explains how to make fields required on a single line of text but it doesn't apply the same way on "attachments" as there is no named control for attachments. I also don't want to disable the save button, i need it to give an error message to the user to explain what is missing.

 

Help!! 

197814_pastedImage_1.png


16 replies

Userlevel 3
Badge +9

This question looks similar.  They used a script to validate the attachment in certain scenarios. You would just need to modify the script to your conditions.

Badge +9

Thanks Brendan. I haven't written java script before. would you be able to take a look at this and let me know if that would work? given that mileageonly is a yes/no field and that i want the attachment to be required when it is marked as "No".

function validateAttachments(source, arguments)
{
    var elm = NWF$('.nf-attachmentsTable');
    var mileValue = NWF$('#' + mileageonly).val();  
    arguments.IsValid = true;
    if (milevalue == 'false' )  {
        if (elm.length > 0 && elm.find('tr').length >= 1) {
            arguments.IsValid = true;
        } else {
            arguments.IsValid = false;
        }
    }
}

appreciate the help happy.png

Userlevel 3
Badge +9

Unfortunately I don't have much experience with JS either.  sad.png   I'd suggest trial/error and see if it works.  

Badge +9

Not a problem. Thanks for your reply happy.png

Userlevel 5
Badge +14

this post might help you

https://community.nintex.com/message/42747?commentID=42747#comment-42747 

Badge +9

Thanks Marian. Would you kindly show me an actual example of how you get the AttachmentsClassId or class name? I tried to insert the .nf-attachmentstable, I tried the guid(id) from the source of the page. but I can't get it to validate and work. it is still allowing the user to save the form.

HELP!!! I need to get this out of the way, it has been 2 days already spent on 1 validation :-(

Userlevel 5
Badge +14

it's one that you can configure in control settings on your own...

Userlevel 5
Badge +14

Hi ‌,

have you managed to resolve your problem?

if so, could you mark the question answered?

#BRGreview‌

Badge +9

Thanks Marian Hatala‌ for the reminder happy.png. and apologies on the delayed response.

I did solve it by adding a function into the min attachments field. It doesn't perfectly work fine in all cases, but I can live with it.

Userlevel 5
Badge +14

sure it an not work (reliably).

you check content of list filed and not form control!

so for NEW form content of 'Mileage only' it's always empty regardless of what you select on form.

for EDIT form it reflects value from list field at moment you opened the form, and again it doesn't follow changes you do on a form.

so I'm not sure whether this satisfies your requirement.

Badge +9

Yup. it was a workaround it to get that requirement mainly out of the way. But it's all chasing me now. I'll retry to do the Javascript and hopefully would be an easy fix. 

Badge +9

Marian Hatala‌, I tried the Javascript that you did in that article again and it worked this time. For some reason it wasn't working before and I thought this would take longer time to fix. That saved my day as users started chasing me for the validation.. 

https://community.nintex.com/message/42747?commentID=42747#comment-42747 

what I had to do is rename the attachments control CSS class name, added the Javascript to the settings of the form, added the validation into the rules on the control.

Thanks again..!

Badge +9

One more question ‌ on this one.

the validation is working fine on the desktop, but it doesn't validate on mobile? Does JS work on mobile? and how can I make it work?

Userlevel 5
Badge +14

JS is not supported on nintex mobile

Badge +7

‌ how did you get ‌'s script to work? will you give an example? I have been trying several different ways to no avail.

Badge +9

Hi Josh,

I got it to work on desktop but unfortunately not on mobile because Javascript is not supported.

So what I did is I added to the form settings the js code.

205397_pastedImage_1.png

then I added some rules on the form whenever there is a total value of an item and it is greater than zero then an attachment is required.

205398_pastedImage_2.png

I had to add couple of other rules to make sure al my cases are covered. So one of the rules look like this :

not(Mileageonly2) && (GetNumberOfAttachments("AttachmentControlClass") < 1) && greaterThan(Reimbursement, 0)


For us, our users can sometimes put all receipts into one pdf/image and put it as one attachment.

But if your users are required to add one receipt at a time for each value inserted, then you can try counting on the form how many items require an attachment and compare it to the total amount found from that JS. 

Again it is working fine for us on desktop but for mobile it is failing to validate.

if you can show us or send us screenshots of which area is having difficulty on your form, we can help troubleshoot happy.png

Reply