Skip to main content
Nintex Community Menu Bar

Make attachments required on condition

  • Jan 20, 2017 5:10 PM UTC
  • 16 replies
  • 58 views
  • Translate All

Forum|alt.badge.img+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

Forum|alt.badge.img+9
  • Jan 20, 2017 5:21 PM UTC

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.

Translate

Forum|alt.badge.img+9
  • Author
  • Novice
  • Jan 20, 2017 7:23 PM UTC

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

Translate

Forum|alt.badge.img+9
  • Jan 20, 2017 9:06 PM UTC

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

Translate

Forum|alt.badge.img+9
  • Author
  • Novice
  • Jan 20, 2017 9:14 PM UTC

Not a problem. Thanks for your reply happy.png

Translate

Forum|alt.badge.img+14
  • Scholar
  • Jan 22, 2017 7:08 PM UTC

Forum|alt.badge.img+9
  • Author
  • Novice
  • Jan 24, 2017 7:35 PM UTC

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 :-(

Translate

Forum|alt.badge.img+14
  • Scholar
  • Jan 24, 2017 10:20 PM UTC

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

Translate

Forum|alt.badge.img+14
  • Scholar
  • Mar 3, 2017 12:06 AM UTC

Hi ‌,

have you managed to resolve your problem?

if so, could you mark the question answered?

#BRGreview‌

Translate

Forum|alt.badge.img+9
  • Author
  • Novice
  • Mar 3, 2017 5:18 PM UTC

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.

Translate

Forum|alt.badge.img+14
  • Scholar
  • Mar 6, 2017 9:52 AM UTC

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.

Translate

Forum|alt.badge.img+9
  • Author
  • Novice
  • Mar 21, 2017 9:37 PM UTC

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. 

Translate

Forum|alt.badge.img+9
  • Author
  • Novice
  • Mar 21, 2017 11:50 PM UTC

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

Translate

Forum|alt.badge.img+9
  • Author
  • Novice
  • Mar 24, 2017 4:59 PM UTC

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?

Translate

Forum|alt.badge.img+14
  • Scholar
  • Mar 25, 2017 8:32 AM UTC

JS is not supported on nintex mobile

Translate

Forum|alt.badge.img+7

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

Translate

Forum|alt.badge.img+9
  • Author
  • Novice
  • Jul 7, 2017 5:10 PM UTC

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

Translate