Xpages: Validation for a field, hopes this helps someone

On August 25, 2010, in xpages, by Mark Hughes

Today i needed to do some validation on an Xpages form.

The scenario
I had a field, it had typeahead enabled on an Xpage.  This view has 6000 documents so a combo box was out of the question.  I didnt really want to do a pick list either since most people know the number they want in the first place.  But i needed a way to figure out  if the value in the field existed in the view.

So i looked at adding a custom validator, couldn’t seem to make that work.  So i looked on the wiki and a few other places and discovered this.  Create a validateExpression validator.

In the expression field you need to add your code to calculate to true or false.  Syntax should be something like

return var1 == var2

Mine looked like

account1 = @Trim(@Text(document3.getItemValueString(‘job’)));
chargetype = document3.getItemValueString(‘jobaccount’);
db1 = new Array(“notes1”, “Applications\\viewpoint.nsf”)
var iffound = “”
if(chargetype == ‘Job’)

{  iffound = @Trim(@Text(@DbLookup(db1,”Project Import”,account1,1)));
return account1 == iffound
{return (@IsMember(account1, @DbColumn(db1,”Accounts7″,1))!= 0)

Then here is the part i didn’t get from the wiki post,  You need to add a DisplayError control next to the field you are validating.  Then set that displayerror to show error messages for that field you are validating.  It will not pop up like the simple can not be 0 or can not be empty messages you get from the default validators.

Anyways I hope this helps someone else.

3 Responses to Xpages: Validation for a field, hopes this helps someone

  1. Mark Hughes says:

    pmr #: 00157, 004

  2. ronald martinez says:

    Hi Mark

    I am interested in the xpage validation you have presented, I tried it but I could get it to work.
    I am validating the existence of an account record in my loan file because there should be no duplicate loan records. If the user enters an existing loan record number the application should respond with an error message and should not save the record forcing the user to hit the cancel key.

    Can you please show me how to do the validation in this case? I am a novice in xpage an your instructions will greatly help me for sure.

    Thank you very much in advance for the attention you will give to my request.

  3. szczecin says:

    Heya! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up losing a few months of hard
    work due to no data backup. Do you have any solutions
    to protect against hackers?

Leave a Reply

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