javascriptvelocitypolarion

Polarion how to get a Javascript variable value to a velocity variable


Is there a way to get the value of a JS variable into a Velocity variable?

In a page script, I have some JS code and I'd like to just parse an output to a Velocity variable but I can't seem to find a way.

The other way around seems to work though, I can use the $!pageContext.put and .get to read a Velocity variable and use it's value into some JS code.

I was also trying to create a page parameter, and I could use the $pageParameter.VARIABLE.valUE() to read the parameter value, which didn't help me.

What I'm trying to do is, inside a page script, have a variable that stores how many work items ranging from today-7d to today. I thought this should work with something like #set($newSrFilter = $transaction.workItems.search.query("type:changerequest AND created:[$today-7d$ TO $today$]")) but the $today variable doesn't work in page scripts for some reason.


Solution

  • I will answer this for future me or anyone else needing this.

    As @Claude Brisson mentioned, reading Velocity variables directly from JS is impossible.

    I was trying to create a query that dynamically selects WIs that were created between a fixed date and today-7days. This is fine via the Polarion widget using Lucene or Velocity, but when I used the $today keyword inside a page script, it didn't like it.

    What I ended up doing is:

    The $pageContext.put() stores the result inside a JS variable

    This now works ok, but I have to refresh the page (a liveDoc) once everytime I open it, as it seems the JS code is not loading properly (or maybe it loads before the Velocity code or something like that).

    I've not tried yet, but I'm thinking maybe the escape ${esc.d} might have worked directly inside a page script, saving me having to create page parameters (something like ${esc.d}today-7d${esc.d}).