wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

XPages and Form Fomulas


One of the unique features in Notes and Domino are form formulas. On a view you can specify a formula that alters the form used to show a form. This is very handy to show the same document reformatted for different stake holders, so they can focus on what is important to them
Form Formulas in Notes Views
Form formulas are a tried and tested solution. So I was wondering what happens when you bring XPages into the mix.In the propeller head properties of a form a developer can specify that an XPage should be opened instead of the form itself. One can specify an XPage for web access and/or client access. So I created and empty form and specified to use XPages instead.
Advanced Form Properties
It turns out that both the Notes client and the classic web views honor the form formula. So you have a new tool for upgrading existing applications and complex forms. If there is a subset a specific group needs to use you can XPage enable the form based on conditions in the document by providing a form formula and an empty form linked to an XPage. Unfortunately the form formula is ignored when you use a view control inside an XPage. Here you need to determine the Page to use in JavaScript. That's a little more complex but also way more flexible. To compute the page name on a per document basis you need to specify a row variable.
The row variable for a view control The variable is hidden in the All Properties panel. For every row of the view the variable will hold an instance of NotesXspViewEntry. You can either use .getColumnValue("columnname") to get a specific column value or .getDocument() to get to the NotesDocument object. You then can use your imagination what to compute. Change forms based on workflow status, authenticated user etc. A formula could look like this:
  1. var curTaste = myRow. getColumnValue ( "Taste" ) ;
  2. return (curTaste == "Sweet" ) ? "FruitWithSugarWarning.xsp" : "Fruit.xsp" ;
What you can't do: open a classic form using this approach. But nothing stops you to add a column where you point to a document in a view in the form database.nsf/viewname/key_or_unid and then the form formula will work.
As usual: YMMV

Posted by on 15 April 2010 | Comments (6) | categories: XPages

Comments

  1. posted by Wayne Allen on Wednesday 22 December 2010 AD:
    Stephan,

    In a similar vein, I have an XPage where several controls use the same server side Javascript to determine whether or not they are visible. I would like to write the routine once (presumably as a Javascript function) then call it from a number of different places on the XPage. Where should I put my Javascript function so that I can call it from the multiple "Visible" properties?

    Cheers,
    Wayne
  2. posted by Stephan H. Wissel on Wednesday 22 December 2010 AD:
    @Wayne: Into a SSJS script library.
  3. posted by bobb on Saturday 17 September 2011 AD:
    I don't understand where I should put myRow? Where I define this value and how?
  4. posted by Stephan H. Wissel on Sunday 18 September 2011 AD:
    @Bobb: read carefully:
    "To compute the page name on a per document basis you need to specify a row variable. The variable is hidden in the All Properties panel"
    .. and look at the picture. There is a red box that highlights the property you need to fill in. You define the value by typing it in.
    The big step: The name of the property that defines the row variable is "var". The value of of the property "var" is the name you can use to deal with the current row of data.
  5. posted by David Newman on Wednesday 01 May 2013 AD:
    I am using a xpages shell application to read and write to a completely different database. The view in the xpages app points to the correct document but I get an error when trying to open the doc even though I have created an xpage with the data componet set to that document/form. So I have an xpage for the form formula name but it won't open. thoughts?
  6. posted by Stephan H Wissel on Wednesday 01 May 2013 AD:
    David,
    post that question on Stackoverflow including the full source and the exact error.
    I would in any case code the XPages name in SSJS when an external nsf is used