Create Temporary JavaScript Variable (object) as Query Object from Existing Retool Query

This code below actually doesn't work as it stands, but if you look at what I am trying to do, I was curious if, in general, this is possible (my syntax is off I'm sure)? Mainly, can I create a query object that is equal to my resource query that I want to run, i.e., the 'queryCurrent' variable used in three places after declared. Trying to avoid using eval().

Thanks!

const run = async () => {

  let queryCurrent = queryUpdateApp();
  
  // Inititalize Runtime
  var startTime = performance.now();
  variableQueryRuntime.setValue(performance.now());
  variableQueryDefinition.setValue(queryCurrent.query);
  variableQueryName.setValue(queryCurrent.id);
  
  // Query Trigger Code
  queryCurrent.trigger({
    // Success Code
    onSuccess: function() {
      // On Success Query
      queryOnSuccess.trigger({
        // On Success Code
        onSuccess: function() {
          // Insert Message Code
          queryInsertMessageJS.trigger();
        }
      });
    },
    // Failure Code
    onFailure: function() {
      // On Failure Query
      queryOnFailure.trigger();
    }
  }).then(
    // Record Runtime
    variableQueryRuntime.setValue(performance.now()-startTime)
  );
  return queryCurrent;
}
run();

What's the end goal and why can't this be accomplished using Retool's native query objects? Sorry, I'm sure I'm missing something here.

Ah the end goal is to creat a function. Out of this so I can do simple insert into all of my existing apps and JavaScript queries to reduce overhead. In any case I figured out why it wasn’t working. let queryCurrent = Object.assign(queryUpdateApp);

1 Like