Couple of questions here so Ill try to make them detailed but short.
1.) I am working a Google Sheet that the end user will scan a serial number into column A and an onEdit() function will process a couple of things. The one thing that I am currently stuck on is getting it to query a GCP SQL Database to return the model information of that serial number. I have the DB connection working as it should. But I am unsure how to pass the scanned value that is in the activeCell and use it in the SQL Statement. Below is where I am at. In the SQL statement I can remove the ' + c and input a serial number and the query works as it should. So how to I use the variable in the query.
2.) How in the world am I going to return the results back to the onEdit() Function and have it update the correct cells? I haven't even gotten to this part just yet so the attempt at coding isn't below. But I know that is going to be the next hurdle so some points would be much appreciated. I like to find snippets and figure out how to piece things together to accomplish what I need. So a good push in the right direction is kinda what I'm looking for here.
Thanks in advance.
function onEdit() {
var row = s1.getActiveCell().getRow();
var cpRange = s1.getRange('B2:J2');
var psRange = s1.getRange(row, 2 , 1, 14);
if( s1.getName() == "Sheet1" ) {
var c = s1.getActiveCell();
var timeCell = c.offset(0,12);
if( c.getColumn() == 1) {
timeCell.setValue(new Date());
}
}
cpRange.copyTo(psRange);
getModelInvType(c);
}
function getModelInvType(c){
const dbUrl = 'jdbc:google:mysql://ConnectionName/DBName';
const user = '*******';
const userPwd = '*******';
const conn = Jdbc.getCloudSqlConnection(dbUrl, user, userPwd);
const stmt = conn.createStatement();
var results = stmt.executeQuery('SELECT * FROM ProductDetail WHERE Serial =' + c);
stmt.close();
results.close();
}