How to easily execute arbitrary, dynamic js code on your AppSheet data at runtime

Considerations:
  • This is not a js tutorial. This is just to present the idea as briefly as possible. In future, separate topics, I will post some useful applications. 
  • This is applicable for Google Sheets as a data source. 
  • The js code will run at Google Cloud servers, has access only to the data written to your source data sheet, not your device, therefore, needed data should be fed into AppSheet columns.
  • The js code you can run is limited to the js libraries available to Apps Script. 

 

Steps:

1. Add this simple function to your sheet using Apps Scripts:

 

function jsCall(data) {
  return eval(data);
}

 

  • This fuction simply executes js code passed to it, and returns its last return value.

 

2. Look at this screenshot:

Capture d’écran 2022-01-26 à 04.10.55.png

  • In the AppSheet column, the function jsCall(), we've just created is used as Spreadsheet formula and will operate on the target column containing the js code. (Columns A and C)
  • The formula columns will contain the arbitrary js code to be executed. This code can be hardwired in the app as a Spreadsheet formula, generated dynamically  using an Appsheet formula, or even entered by the user through an AppSheet form
  • When your js code is not static, take note of the apostrophe "'" that your code-generating formula will have to generate at the start of the code; to force the spreadsheet to treat the code as brute text not a formula it would evaluate.
  • You can include dynamic variables in the codes using values stored in AppSheet columns (in case of Appsheet formulas), or in the Spreadsheet columns (in case of Spreedsheet forumlas), using the CONCATENATE commands respectively.

 

5 0 110
0 REPLIES 0
Top Labels in this Space