[4.2] - Run server-side selectQuery client-side

Posted by IramK on 03-Oct-2016 11:17

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

Posted by Mohammed Siraj on 06-Oct-2016 06:54

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:

http://documentation.progress.com/output/rb/doc/index.html#page/rb/avoiding-mixing-client-side-and-server-side-apis.html

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]

All Replies

Posted by Mayank Kumar on 06-Oct-2016 03: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

Posted by IramK on 06-Oct-2016 03:55

Yes, but I wanted to know how I can get a selectQuery to work with an EVAL block.

Posted by Mohammed Siraj on 06-Oct-2016 06:54

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:

http://documentation.progress.com/output/rb/doc/index.html#page/rb/avoiding-mixing-client-side-and-server-side-apis.html

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]

Posted by IramK on 06-Oct-2016 08:17

Thanks [mention:78c86023544844079dc6455a4a7a4d57:e9ed411860ed4f2ba0265705b8793d05] . That was what I was looking for.

Cheers.

Posted by IramK on 07-Oct-2016 03:40
Hello Siraj,
 
Is there a way I can add a value to that server-side selectQuery? See example below:
 
var accountId = 12345;
#EVAL[rbv_api.selectQuery2(“select name from account where id=” + accountId, 0, 1); ];
 
The above is just an example. Obviously we need to extract values from select Query using the technique you suggested, however, I was just wondering if we can use variables like that?
 
Cheers,
Iram
 
Posted by Mohammed Siraj on 07-Oct-2016 04:10

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.

This thread is closed