0
votes

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

3

3 Answers

1
votes

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).

3
votes

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.

-1
votes

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

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