• vadim@workflowexcellence.com
  • Utah, United States

Nintex Forms – Attachment Required

If you haven’t seen Nintex Forms, go and either download a trial or a hosted trial.  You’ll find that if you have any number of fields in your list and generate a Nintex Form for it, it will automatically generate a visually appealing, user friendly form.  It’s a very quick and easy way to have a nice form for user.

As part of a form for a List or even for a Task, a user can attach one or more documents.

What if you want a user to ALWAYS attach a document, and you don’t want to allow a user to be able to complete the form without an attachment?

The easy way I found to do this, would be to create a custom validation function, link it to one of your fields (ie. the Title field).  If someone fills in the form and presses Save, the validation function will be called and if there’s no attachment, validation will fail and the Save will not be allowed to proceed.

The following is the most simple Nintex Form, based on a list with just a Title field.

Form Design

To set a custom validation funtion, you simply double click on the Title text box and that will bring up the Control settings.  In the Validation section, you add a javascript function name.  That will be the function that is called when you leave the Title field or press the Save button.

Validation Function

Based on the configuration above, I need to create a javascript function called “validateAttachments”.

In the form design, on the ribbon click on Settings.  Then expand the Custom Javascript section and that’s where you put in the Javascript.

Custom Javascript

Here’s the Javascript :

function validateAttachments(source, arguments)
{
 var elm = document.getElementById("idAttachmentsTable");
 var elmAttachmentRow = document.getElementById("idAttachmentsRow")
 if ((elm != null && elm.rows.length > 0) && (elmAttachmentRow != null))
 {
   arguments.IsValid = true;
 }
 else
 {
   arguments.IsValid = false;
 }
}

The Javascript simply checks the number of attachments in the current form.  If you add a custom validation error message, it will give the user and idea as to why validation failed.

Error Message

In the above example, I just put in a title value and presses Save.  You can see the message is telling us that either the data is invalid or you haven’t added an attachment to this form.

Below, you can download this form and use it on a SharePoint Custom List with just a title field.  It’s a very simply form and I didn’t bother with sharing a List Template, since you can just go to create a Custom List and then import this form.

Downloads

Form Design: Download Form Design

Leave a Reply

Your email address will not be published. Required fields are marked *