Oct 22, 2013, 3:56 PM
10 Posts
topic has been resolvedResolved

Validate Field From Button

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 9.0
  • Role: Developer
  • Tags:
  • Replies: 2

Hello - I would like to validate a field from a button that also runs an agent.  Basically, I want to first check if the field is blank.  If it is, then prompt the user to enter a value.  After the field is filled in, then run an agent, then save the document.  Is there an easy way to do this?  I did try Tommy Valand's method from this post (http://dontpanic82.blogspot.com/2010/03/xpages-making-validation-behave.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+dontpanic82+%28DontPanic+-+a+blog+about+Lotus+Notes+%2F+Domino%29&utm_content=Bloglines) but I don't know if it is really necessary or not.

Thanks for your help in advance.

Oct 23, 2013, 5:23 AM
261 Posts
1 field and a button


Add a field to your XPage and a button. Mark the field as required. By default if you click a button, all fields will be validated first, so on the field's onclick event, you can directly add the code to run the agent ( session.getAgent("nameOfAgent").run() ) and save the document ( doc.save() ). 

If you need to pass parameters to the agent, use the .runWithDocumentContext() method.

I made some assumptions in my answer, so you might to tweak it for your situation.


Oct 27, 2013, 12:17 PM
366 Posts

if you want to use partial refresh, you can code the client side javascript of the button to do the field validation and return a true or false.  The Server Side button code will only execute if the client side code returns true.  So you could call the agent from ssjs code upon the successful completion of the csjs code