Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 16150

How to Run onEdit/onChange function in Google Apps Script on Data pulled Dynamically using Query

$
0
0

So, I am pulling some data from a Google Sheet let's say A into sheet B.

In the Sheet B, I am fetching the data from Sheet A using Query() formula.

What I need is when a new row is added to Sheet B (pulled when a new row is added to sheet A) then run a script.

What the script will do is choose a random value from the H column which is dropdown type.

The script which works by the way on non dynamic data is:

function onEdit(e){    var range = e.range;    var row = range.getRow();    const agentColumnName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(row,8);    const dropdownValues = agentColumnName.getDataValidation().getCriteriaValues()[0];    var value =     agentColumnName.setValue(dropdownValues[Math.floor(Math.random() * dropdownValues.length)]);}

But I want to run this on the Dynamic Data that is when a new row is added by the Query function. I read that onEdit and onChange only runs on user entered data ... but is there any workaround for that?

Please help me fix the script to work on dynamic data.... thanks


Viewing all articles
Browse latest Browse all 16150

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>