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.
- 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";
- Declare FieldItem as notesitem , FieldName as string and FieldLabel as string.
- Create a function named Validation and copy the following code:
Function Validation Validation=False 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 validation=True End Function
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 SearchDomino.com 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.