In a Javascript report, how can I pass a variable value betw

Posted by Rollbase User on 08-Sep-2012 10:29

It looks like a variable define in the header cannot be passed to a loop iteration (undefined variable). Or a variable define in a loop iteration cannot be pass to another iteration (as it is a local variable) How can this be done?

All Replies

Posted by Admin on 08-Sep-2012 13:41

We do not offer this functionality at this time. We can consider this as an enhancement.

Posted by Admin on 09-Sep-2012 00:40

Hi Claude,



Regarding variables defined within loops, yes they are local variables and should not be accessible outside the loop. I believe this is what Pavel is referring to.



However, variables defined before and outside a loop are accessible, at least in Formula fields. Do you mind posting your code here? If you'd rather not post it here perhaps you can email me directly.



Thanks,

Matt

Posted by Admin on 09-Sep-2012 23:11

Here a simplified example of the JS report code :



--- Header Section ----

var gvar = 99; // global variable



--- Loop Body ----

rbv_api.println (gvar); // error gvar undefined

lvar += 1; // error lvar undefined

rbv_api.println (lvar);



--- Footer Section ---

// empty





I have tried to replace global variable with a company-wide setting using the rbv_api.setFieldValue() function but it has not effect



Posted by Admin on 10-Sep-2012 01:23

Reports do not run in Transaction, so they're not supposed to make persistent data changes.

However I will enable rbv_api.setFieldValue() to make non-persistent changes - that will work for your purposes. Check again in 3.8.0 release.

Posted by Admin on 10-Sep-2012 12:19

Claude, I see in your code you've defined variable 'gvar' but where is variable 'lvar' defined?



Matt

Posted by Admin on 10-Sep-2012 15:28

If I defined lvar with a var statement in the header, it would behave as gvar.

If I defined lvar with a var statement in the loop, it would behave as a local variable.



I made an "implicit" declaration of lvar (no var statetement).

I was hoping that an implicit declaration would have behaved like a global variable defined before the loop but it didn't.



It failed to work In all 3 cases.

Posted by Admin on 11-Sep-2012 00:53

Hi Claude,



Perhaps you can send me an email or submit a support ticket pointing me to where I can see your full JavaScript code?



Thanks,

Matt

Posted by Admin on 13-Sep-2012 23:19

Hi Claude,



Thanks for sending the link via email -- I now see what you are talking about more clearly (as Pavel already had) and his response is the current case: the header is parsed and output completely separately from the loop iterations so there is no current way to pass variables from header to loop.



Pavel is working on a solution for this as mentioned above in the upcoming release.



Hope this will help you out,

Matt

This thread is closed