The session scope can handle complex objects. Creating a string reduces maintainability quite a bit. I would create the stuff like this:
var prepopulate = [];
prepopulate.push({ "name" : "IssuingCountry", value : "United Stated of America"});
prepopulate.push({ "name" : "ReceivedDate", value : [date1, date2]);
sessionScope.AddingNewLine = prepopulate;
Then is the afterPageLoad
(which runs before renderResponse
) you do something like this (omitted the test for valid field names):
if (!sessionScope.AddingNewLine) {
return;
}
var prepopulate = sessionScope.AddingNewLine;
for( var i = 0; i < prepopulate.length; i++ ) {
var oneItem = prepopulate[i];
FInvoiceDoc.setValue(oneItem.name, oneItem.value);
}
// reset
sessionScope.AddingNewLine = null;
So the 2 important differences: use afterPageLoad and use a complex object, not a wild string. Instead of an array, you might want to use a object since you have a special use for CPrompts.
Btw you declare a variable inside a condition. Only the fact that JS doesn't use block level variables prevents the code from failing if you don't have CPrompts in your string. So the complex object might be:
var prepopulate = {};
prepopulate.cprompts = ["some","prompts"];
prepopulate.fields = [];
prepopulate.fields.push(....);
Hope that helps