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?
We do not offer this functionality at this time. We can consider this as an enhancement.
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
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
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.
Claude, I see in your code you've defined variable 'gvar' but where is variable 'lvar' defined?
Matt
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.
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
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