Hello all,
I'm a business user building out an app on Rollbase. I want to write formulas using the Rollbase API in script components in the page editor but can't get it to work. A simple example would be to display the number of records in a view, which I am writing as:
<script>
var totalRecords = rbv.getCount(109623509);
document.write(totalRecords);
</script>
What am I doing wrong?
Thanks for your help!
You can use Rollbase server-side API in EVAL[ ] block. This block will be evaluated on server side during page rendering process.
Thank you - what is the correct syntax? I tried
<script>
#EVAL[
var totalRecords = rbv.getCount(109623509);
document.write(totalRecords);
]
</script>
but that didn't work...
Hello,
Try using this syntax since you are missing the _api part. rbv_api.getCount();
Thank you,
Gian
Thank you, but that still doesn't work...
This is a little ticker: rbv_api lives on server side, while document.write - on client side. So try this instead:
<script>
document.write(#EVAL[rbv.getCount(109623509)]);
</script>
Content of EVAL block will be replaced by calculated value in HTML sent to the browser.
document.write(#EVAL[rbv_api.getCount(109623509)]);
Got it, thank you very much!
OK, stumped again...
I want to use a script component on a portal page to loop through records and display fields in a table. Everthing works fine if it's with a token within html:
{!#LOOP_BEGIN.all#112247192}
<p>It's a {!product_name}</br></p>
{!#LOOP_END.all}
But when I try to get the field value inside script, I can't get it to work:
{!#LOOP_BEGIN.all#112247192}
<script>
var text = {!product_name};
document.write(text);
</script>
{!#LOOP_END.all}
(Although the odd thing is it seems to work for numeric fields, but not text fields.)
I've tried everything I can think of - with #EVAL[] blocks, all the rbf and rbv api queries related to "getField"... what am I missing??
It is not working mainly because the parsed value of the token {!product_name} is treated as a variable in your JavaScript code. If you had a product name TEST, the code will be evaluated as:
<script> var text = TEST; document.write(text); </script>
The code basically returns an error because TEST variable is not defined.
Enclosing the token with a single or double quotation mark should fix the problem.
Perfect, thank you!