Manage Learn to apply best practices and optimize your operations.

Compact code for field validation

This piece of code helps reduce the number of lines of code that are usually written to validate fields on a form.

These steps and this piece of code helps reduce the number of lines of code that are usually written to validate fields on a form.

  1. Create a hidden field multi-value "fieldlist" on the form and list all of the fields that need to be validated in the format of <Field Name>"~"<Field Label>".

    Example: "IR_txIA~Inventory Admin":"IR_txItem~Item":"IR_Justify~Justification";

  2. Declare FieldItem as notesitem , FieldName as string and FieldLabel as string.

  3. Create a function named Validation and copy the following code:
Function Validation 
 Set  fielditem=doc.getfirstitem("flist") 
 Forall v In fielditem.Values
  fieldname=Strtoken(v, "~", 1)
  fieldLabel=Strtoken(v, "~", 2)
  If Trim(uidoc.fieldgettext(fieldname))=
"" Then 
   Call ValidationMessage(uidoc,
fieldName, fieldLabel) 
   Exit Function   
  End If
 End Forall
End Function

That's all!

Even if there are n number of fields on the form, only these few lines of code are required to validate all of them . In my case, all of the fields are text; for other data types, the code can be enhanced on the same logic.

Do you have comments on this tip? Let us know.

This tip was submitted to the tip exchange by member Priyanka Deva. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Dig Deeper on LotusScript

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...