Hello,
I just noticed that there is a way of running server-side script on client-side using an EVAL[] block. I have been trying to achieve that for a selectQuery, however, could someone post some code on how I can run server-side selectQuery on client-side please?
Cheers.
Iram
Iram, EVAL blocks are used to compute and return String results into Templates/HTML Components. Yes, they can also be used to embed computed simpe types like Numbers/Strings (as strings) into code snippets of script components.
However, you need to ensure that on evaluating the expression and substituting the value in code snippet the code syntax should still be valid.
This is supported by the platform, however, designing it is a fairly complex task. One basic example is listed here:
Now, regarding selectQuery2 - server-side API. This returns a 2D array as result. hence, it needs to be processed into a JSON string and made available to your code snippet.
Attached with this post is a sample application, with two script component examples.
One that iterates over all the records of an object and prepares a string result for output.
Second that iterates over all the records of an object and prepares a json string for output. In the second case, on client-side you can parse the json string back into an object.
Note: Using EVAL blocks in client-side component eventhough is a faster way of embedding dynamic values for client-side processing, it is fairly complex because of syntax and evaluation constraints. The EVAL block will be evaluated on server-side and the resulting string expression will be substituted in the code snippet. User needs to ensure that on substitution, code snippet syntax is still valid. On the client-side, this code snippet will then be executed in browser environment.
[View:/cfs-file/__key/communityserver-discussions-components-files/25/TestServerSideScriptEval_5F00_v3.xml:320:50]
Hi Iram,
We already have the client side counter part of this API (rbf_selectQuery). Could you please share the use case to help us understand the requirement.
Regards,
Mayank
Yes, but I wanted to know how I can get a selectQuery to work with an EVAL block.
Iram, EVAL blocks are used to compute and return String results into Templates/HTML Components. Yes, they can also be used to embed computed simpe types like Numbers/Strings (as strings) into code snippets of script components.
However, you need to ensure that on evaluating the expression and substituting the value in code snippet the code syntax should still be valid.
This is supported by the platform, however, designing it is a fairly complex task. One basic example is listed here:
Now, regarding selectQuery2 - server-side API. This returns a 2D array as result. hence, it needs to be processed into a JSON string and made available to your code snippet.
Attached with this post is a sample application, with two script component examples.
One that iterates over all the records of an object and prepares a string result for output.
Second that iterates over all the records of an object and prepares a json string for output. In the second case, on client-side you can parse the json string back into an object.
Note: Using EVAL blocks in client-side component eventhough is a faster way of embedding dynamic values for client-side processing, it is fairly complex because of syntax and evaluation constraints. The EVAL block will be evaluated on server-side and the resulting string expression will be substituted in the code snippet. User needs to ensure that on substitution, code snippet syntax is still valid. On the client-side, this code snippet will then be executed in browser environment.
[View:/cfs-file/__key/communityserver-discussions-components-files/25/TestServerSideScriptEval_5F00_v3.xml:320:50]
Thanks [mention:78c86023544844079dc6455a4a7a4d57:e9ed411860ed4f2ba0265705b8793d05] . That was what I was looking for.
Cheers.
Iram, the above stated example will not work. The EVAL block processing is independent of the context in wich it is used. You can use EVAL results in script but not the other way round.