Validation Rule: Conditionally Require User to add Attachment


Badge +6

Within the Nintex form, I have 4 different attachment fields.  I need to validate before the user hits ‘Submit’, that there is at least one attachment loaded into one of those fields (could be any of the 4 attachment fields), when another field has a specific value.  I believe, after doing some research, that custom JavaScript will be needed to build this validation rule.  Basically, I need to make sure there is an attachment (conditional formatting to make a field required), when a specified field has a specific answer.


14 replies

Userlevel 5
Badge +14

have a look on this

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

in your case validation formula might look like

AnotherControl == 'X' && 
(GetNumberOfAttachments('AttControlClass1') +  
GetNumberOfAttachments('AttControlClass2') + 
GetNumberOfAttachments('AttControlClass3') +  
GetNumberOfAttachments('AttControlClass4') < 1)‍‍‍‍‍‍‍‍‍‍‍‍
Badge +6

What does 'X' mean in your formula? 

What values do I put in the 'AttControlClass' fields? 

Would that be the names of the attachment controls?

Thank you!

Badge +6

Sorry, I have a few more things to add.

Where would this rule be put on the form?  I was thinking of encompassing the 4 attachment fields inside a panel and putting the rule on that panel.  Additionally, the requirement of at least 1 attachment is determined based on outcome of 2 other fields.  Would this still work? 

If field A = 'Yes' and Field B = 'True', then there needs to be at least 1 attachment within the 4 attachment fields.

Thank you!

Userlevel 5
Badge +14

quite a big homework with so many questions happy.png

What does 'X' mean in your formula? 

that's placeholder for your 'specific value' in 'another field'

What values do I put in the 'AttControlClass' fields?

these are CSS class names configured for single attachment controls. class names configured for single controls have to exactly match with ones used in validation formula

216384_pastedImage_6.png

Would that be the names of the attachment controls?

controls' names play no role

Where would this rule be put on the form?  I was thinking of encompassing the 4 attachment fields inside a panel and putting the rule on that panel.

in a whatever validation rule.

you can assign the to a panel as you depicted

Additionally, the requirement of at least 1 attachment is determined based on outcome of 2 other fields.  Would this still work? 

sure. you just need to extend validation formula with one another expression

If field A = 'Yes' and Field B = 'True'

be carefull. first of all comparison operator is == (or better ===), single = is assignment operator.

at second, if FieldB evaluates to string "True" then your formula is correct. but if it evaluates to boolean TRUE (eg. yes/no control) do not compare it with string! boolean variable is being used as single expression on it own.

so, your overall formula might look like

FieldA == 'Yes' && 
FieldB &&
(GetNumberOfAttachments('AttControlClass1') + 
GetNumberOfAttachments('AttControlClass2') + 
GetNumberOfAttachments('AttControlClass3') + 
GetNumberOfAttachments('AttControlClass4') < 1)‍‍‍‍‍‍‍‍‍‍‍‍
Badge +6

Thank you Marian.

My attachment controls look like the following S.S.

We have predefined CSS Class for different fields.  Each attachment control has it's own name.  If we do not have unique values in the CSS Class field, will what I am trying to accomplish not work?

My complete formula: Major_TH_Project=="Tower Integration Project" &&New_Renewal_Amendment!="Termination"&&(GetNumberofAttachments('CapReqAttachment') + GetNumberofAttachments('MultiReqAttachment') + GetNumberofAttachments('QuoteAttachment') + GetNumberofAttachments('SOWAttachment') >1)

***I also tried the formula using what we do have in the CSS Class field currently.  Neither formula is highlighting the panel as being required when no attachments are included.

Thank you! happy.png

Badge +6

Sorry for multiple responses...I thought of something to try but still no luck.  I removed what was defaulted into the CSS class and added the code onto the panel (same outcome for the fields!).  I then gave each attachment control the unique value below in the CSS Class field.

Current formula: Major_TH_Project=="Tower Integration Project" &&New_Renewal_Amendment!="Termination"&&(GetNumberofAttachments('AttControlClass1')+ GetNumberofAttachments('AttControlClass2')+ GetNumberofAttachments('AttControlClass3') + GetNumberofAttachments('AttControlClass4') >1)

Again, when I make the selections for the first 2 criteria above, the panel in which the validation rule resides, is not indicating it is now required.

Thank you!

Userlevel 5
Badge +14

We have predefined CSS Class for different fields.

they are just default (formatting) classes.

you can define as many classes as you need, just separate them by a space.

eg

216399_pastedImage_5.png

will what I am trying to accomplish not work?

No.

not with my with my GetNumberofAttachments function.

it's much easier to identify controls by their (unique) CSS class (or by a javascript variable for controls which support it) then by name.

I also tried the formula using what we do have in the CSS Class field currently

they are very generic classes and they are used on plenty of other (type of) controls.

very likely on other type of control formula will fail or cause errors.

Again, when I make the selections for the first 2 criteria above, the panel in which the validation rule resides, is not indicating it is now required.

ops! sorry, my mistake.

sum of all attachments over four controls has to be less the 1 to invalidate form (not greater then 1).

I updated my above formulas.

Badge +6

Good Morning Marian,

Below is a screen shot of my attachment controls.  Each of the 4 attachment controls are setup the same (but with the number incrementing), so that each has their own unique AttControlClass name.

Below is my updated formula, showing the 4 attachment controls added together are less than 1.

Unfortunately, this rule is still not working.  When I have the first 2 criteria selected within the form, and do not add any attachments, it is not indicating the attachments are required.

Thank you.

Userlevel 5
Badge +14

what are 'Major_TH_Project' and 'New_Renewal_Amendment'?

if they are named controls - they should have been highlighted in red. you can not type them in manually, you have to select them from above Named controls list.

Badge +6

They are named controls.  It seems the screen shot I took, did not capture the red highlighting of the named controls.  Below is the formula, copied directly from the formula field.

Major_TH_Project=="Tower Integration Project" &&New_Renewal_Amendment!="Termination"&&(GetNumberofAttachments('AttControlClass1')+ GetNumberofAttachments('AttControlClass2')+ GetNumberofAttachments('AttControlClass3') + GetNumberofAttachments('AttControlClass4') <1)

Badge +6

Hi Marian,

Below is a screen shot of my validation formula (showing the fields as being Named Controls).

Additionally, I have included the Custom JavaScript, which I had not embedded before, but found in one of your other posts about validating Attachment Controls.

Lastly, I have updated the CSS Class field to match what I saw in your other posts.

Unfortunately, my validation rule is still  not working.  It is never requiring me to add an attachment.  Please let me know if I can provide any further information.

Thank you so much for your time and patience! happy.png

Userlevel 5
Badge +14

ok, let's try it step by step...

try to reduce validation formula just to 

GetNumberOfAttachments('AttControlClass1') <1

and try to submit form with no attachment in respective 'AttControlClass1' attachment control.

does it prevent form to submit ?

Badge +6

Good Morning Marian,

Great Idea!  I updated the formula to only look at the one attachment control.  It worked.  The form required me to add an attachment prior to submitting.  I went ahead and added in the formula to look at all 4 controls.  That is also working!! happy.png   Again, moving forward I added in the Major_TH_Project=="Tower Integration Project" (but with single quotes instead of double quotes, and I added it after the GetNumberofAttachments formula.  It is also working.  It only requires the attachments when Major_TH_Project equals Tower Integration Project.  Lastly, I added the New_Renewal_Amendment!="Termination" portion back into the formula at the end, but I used single quotes around Termination.  It now works!!!  I am not sure if it was the order of the elements and formula or the difference between single and double quotes.  BUT, the formula is working as it should!!!  When Major_TH_Project = Tower Integration Project and New_Renewal_Amendment equals anything but Termination, it is requiring an attachment be added.  If I change the New_Renewal_Amendment field to Termination, it removes the requirement of attachments.

I cannot thank you enough for your patience with walking me through this!!!  I had tried stripping the formula down to almost nothing before, but could not get it working.  Glad it's working now!!

Thank you!!! happy.pnghappy.png

Userlevel 5
Badge +14

great!

remember to mark correct answer happy.png

Reply