Posts Tagged ‘ InfoPath Validation ’

InfoPath 2010 – Validating the Attachments Field

InfoPath 2010 has its ups and downs. For the most part it makes things extremely easy. However, you’ll still run into the occasional roadblock while working with InfoPath forms.

I recently ran into one such roadblock. The issue was being able to apply validation rules to the attachments field. To my surprise, InfoPath does not let you select the Attachments field to apply rules, making it a challenge apply validation on attachment fields. Also, if you go into the advanced view and select the repeating ‘:attachmentURL’ field inside of the Attachments group and apply formatting to that field it just doesn’t work.

So, I had to come up with a custom solution. Now, given one of the major advantages of using InfoPath in the first place is not having to use any code behind, I didn’t want to have to add custom code to my form.

My solution involves 3 steps:

1.) Create a field in addition to the attachments field. In my case, I called the field I created Attachment Validation.

2.) Drop your field onto the form and remove the borders and background. Then set the default text to ‘Attachments:’

InfoPath 2010 Attachments Field Validation

3.) Finally, lets apply some validation to this field. Right click the field on your form and select Rules > Manage Rules.

In my case, I needed to make sure there was at least one attachement. So, I counted the :attachmentURL instances and checked if there were more than 0. To do this, I used a custom expression:

Now with all of that complete you will have a separate field that validates the attachments field and if there are no attachments, the text in the left hand column will be surrounded in the standard red dashed border.

InfoPath 2010 Validation on Attachments Field


To get to the ‘:attachmentsURL’ field you need to create the validation make sure you go into Advanced View of the fields.

InfoPath 2010 Attachments :attachmentURL field advanced view