0

I have question regarding session.evaluate in SSJS. In a keyword document I have some @formula stored which does some conversion of data. Lets say this is would be:

@left(fieldname;2)

If the fieldname contained 'hello' this would result in 'he'. Nothing to fancy here. Now I would like to use this in an xpage.

I wrote a function called executeFormula(doc). I call this function from an action on a xpage. This xpage contains 1 notes document datasource. The function call is

executeFormula(datasource.getDocument(true))

Now for some reason the @formula is never calculated correctly. Do I need to save the document first before I can use session.evaluate(kwFormula,doc) or is the @formula wrong in some way?

p.s. I forgot to mention that this code is working inside a customvalidator

jjtbsomhorst
  • 1,667
  • 11
  • 28

3 Answers3

3

Without seeing the code for the executeFormula(doc) function it is very difficult to know exactly how session.evaluate is being called.

I would suggest taking the function out of the equasion for the moment and create a simple test page with the document source and a simple computed field with the session.evaluate in it so that you can see the result. Given your examples above the computed field would be something along the lines of

session.evaluate("@Left(fieldname;2)",xspDoc.getDocument(true));

Once you get acceptable results back then you can move it into your function and verify that it is working there also.

Don't forget that session.evaluate returns a vector so you may beed to do a .getFirstElement() on the returned value if it is not null.

Declan Lynch
  • 3,345
  • 17
  • 36
  • Thanks for your comment. The code that is in the function does nothing more then retrieve a keyword document from a view and read the contents of the value field. In this value field I stored the @formula stated before. – jjtbsomhorst Jul 13 '12 at 04:43
1

If you're using it in a custom validator, the values posted from the browser/client haven't updated the data model (in your case, the document) yet. This happens after validation is successful.

I imagine it might work for some fields (e.g. fields that are updated after a successful refresh, or stored fields in an existing document).

Tommy Valand
  • 868
  • 6
  • 10
-1

Actually no need of mentioning the document, eg:- session.evaluate("@username") is enough.

For yours session.evaluate("@left('hello';2)") will work.,

Ramkumar
  • 874
  • 11
  • 27
  • Ofcourse, @left('hello',2) will work. The problem is that document specific @formula is not correctly handled. for example: @left(fieldname;2) – jjtbsomhorst Jul 13 '12 at 11:44