0

I am trying to output som script using SSJS from a computedField like so:

var outScript = "<script>var data = " + datad.toString() + ";</script>"

The problem I have is that the computedField is within a doccollection repeat so I need to make the variable dynamic because I later need to access only the variable from the current entry using client side javascript (also within repeat)

How do I write to make the "data" variable dynamic within my repeat?

I know can create the variable using noteid or index, but I need to know how to write to output the variable i.e data1, data2 etc.

Hope you understand, a bit complicated to explain. problably an easy answer I havn't thought of

thanks Thomas

Thomas Adrian
  • 3,543
  • 6
  • 32
  • 62
  • It works, but it is very bad idea to compute script by computedText control. By default it gets evaluated several times during every refresh (because of JSF life cycle). – Frantisek Kossuth Jul 20 '17 at 17:52

1 Answers1

1

You could use the repeat's indexVar to save the data with a distinct key for each repeat entry:

var outScript = "<script>window.data_myRepeat_" + iRepeat.toFixed(0) + " = " + datad.toString() + ";</script>"

Here, it is assumed that the repeat's ID is "myRepeat" and indexVar is "iRepeat".

xpages-noob
  • 1,569
  • 1
  • 10
  • 37