I’m dynamically creating a form with Solution Model. I have a case when I try to add a text area linked to a form variable (also a solution model) with a default value. The default value is taken from a dataset. If it contains multi lines, as normal if entered by a text area, then that value is not assigned to the variable and hence, not displayed by the text area.
The default value as shown in the developer debugger is:
"line 1
line 2
3"
My code is:
var txtAnswerText = form1.newVariable("vTextAnswer_"+i,JSVariable.TEXT);
txtAnswerText.defaultValue = "'" + dataset.getValue(i,5)+"'";
var new_editbox = form1.newTextArea(txtAnswerText,200,i*25+startY,375,50);
Is there a way to parse the variable or assign it differently?
Look at working with solutionModel as if you were doing things at designtime.
If you set the default value of a variable at design time, you will not actually have newlines in it.
For example you won’t have at design time
var x = 'a
b
c';
but something like```
var x = ‘a\nb\nc’;
var x = ‘a
b
c’;
So the actual already-evaluated newline character(s) you have in that value must be converted to "\n"(or \r\n) before being assigned to the default value of a variable - didn't try the "\" approach with solutionModel but that one might work as well. When that variable is first initialized (for runtime usage) after being created through solutionModel, it's default value will be evaluated just as it happens with design time defined variables.
var txtAnswerText = form1.newVariable("vTextAnswer_"+i,JSVariable.TEXT);
txtAnswerText.defaultValue = ("'" + dataset.getValue(i,5)+"'").replace(/\r\n/g,"\\r\\n").replace(/\n/g,"\\n");
var new_editbox = form1.newTextArea(txtAnswerText,200,i*25+startY,375,50);
That view shows that your variable actually contains the character with code 10 for new line - not two chars '' and ‘n’ as I suggested above.
The short form above (from the same view) is just a convenient way of showing it on one line.