May 29, 2014 8:12 AM
5 Posts

Why this SSJS is not working

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 3

I am trying to populate array in 'Before Render Response' page event storing data in requestScope/viewScope and use the data as source for repeat. However, I can't get scope variable to store any data:

beforeRenderResponse code is:
    doTest();

SSJS that is included in the page is:

function doTest(){
 var q=new Array();
 loadStructure(q);
 requestScope.x=q; // tried also requestScope.put('x',q) with the same result
 var y=requestScope.x;
 println('z='+q['A1']);
 println('q='+requestScope.x['A1']);
 println('s='+y['A1']);
 println('w='+requestScope.x);

 requestScope.x['A1']='AAAAAAAAAAAAAAAAAAAA';
 println('p='+requestScope.x['A1']);
}

function loadStructure(r){    
    r['A1']='aaaaaaaaaaaaaaaaaaaaaaaaaaa';    
    return r;    
}

Console reads:

[15EC:0203-14B8] 05/29/2014 08:08:56 AM  HTTP JVM: z=aaaaaaaaaaaaaaaaaaaaaaaaaaa   <-- output as expected
[15EC:0203-14B8] 05/29/2014 08:08:56 AM  HTTP JVM: q=undefined    <-- did not store value
[15EC:0203-14B8] 05/29/2014 08:08:56 AM  HTTP JVM: s=undefined   <-- nothing retrieved
[15EC:0203-14B8] 05/29/2014 08:08:56 AM  HTTP JVM: w=[] <-- value exists as empty array
[15EC:0203-14B8] 05/29/2014 08:08:56 AM  HTTP JVM: com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript action expression

Does not matter if I use viewScope or requestScope, or put and get methods in the same to access stored value

 

What am I doing wrong?

Domino 8.5.3FP6/ Win2008 32 bit

 

 

May 29, 2014 8:48 AM
366 Posts
Not Valid in beforeRenderResponse

I don't believe that either on of those scopes are valid when set in beforeRenderResponse.

What happens when you try using a session scope variable?

Why does it need to be in the beforeRenderResponse event?

May 29, 2014 11:06 AM
5 Posts
yes, they are valid

requestScope and viewScope are valid everywhere.

I narrowed it down to if I associate array of basic types (e.g. string) it would work, but it won't accept array of custom object.

So I am putting a custom object  that contains memeber array , and that seems to be working.

Strange

Jul 10, 2014 3:26 PM
170 Posts
Change to this

Change

 loadStructure(q);

to

q= loadStructure(q);

that should fix your code

 

/Fredrik

Http://www.xpagedeveloper.com