Feels like I am on the one-yard line but just do not know enough yet about GAS syntax, etc.
Here is the call as you instructed:
var to = '14086567070';
var body = 'sendSMS test';
sendSms(to,body);
And here is the sendSms function in a separate script:
```function sendSms(to, body) {
var messages_url = "https://api.twilio.com/2010-04-........";
var payload = {
"To": to,
"Body" : body,
"From" : "14104313008"
};
var options = {
"method" : "post",
"payload" : payload
};
options.headers = {
"Authorization" : "Basic " + Utilities.base64Encode("AC291d5ff9701......"
};
UrlFetchApp.fetch(messages_url, options);
}
Twilio keeps kicking it back. The "to" and "body" parameters do not seem to be passing. Appreciate the help and once this hurdle is crossed, I will go through the full GAS tutorials and training. Thank you.
@gp9293 Can you please share code … mine is not working with if(e.changeType == ‘INSERT_ROW’), BUT without it its working fine …
My whole code :
function onChange(e){
if(e.changeType == ‘INSERT_ROW’){
var sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“Sheet1”);
sh.getRange(“B10”).setValue(100)
}
else {
return;
}
}
var sheet = SpreadsheetApp.getActive();
ScriptApp.newTrigger(“onChange”)
.forSpreadsheet(sheet)
.onChange()
.create();
Glide can’t directly call a function with a parameter. You need to set up an onChange trigger in the google sheet that calls the function. That is the only trigger that will work other than a time based trigger. Unfortunately any change in the sheet or via glide will execute the onChange trigger, so you would have to change your logic to determine if a row is new or not. Maybe set a flag in a column if the new row has been processed by the script and then skip any rows that have the value set. The function can be named anything you want, but cannot have any parameters like (e).
What are you trying to achieve with your script? Is is something that could be done in Glide instead? Looks like you are just setting a single value in a single cell?
umm, that’s not true.
There is an event object that can be accessed when an onChange event has fired.
You can use it to discover (for example) the changeType and the source (the latter isn’t documented, but it is available - I use it regularly to discover which sheet and/or range triggered the event)
Really? I thought the triggers didn’t pass an object. I thought that an object was only passed if you are working directly within the sheet. Might have to play around with that again.
function on_sheet_change(event) {
var sheetname = event.source.getActiveSheet().getName();
var change = event.changeType;
console.log([sheetname, change]);
}
Then do something in the app that causes a new row to be added, and check the logs. This is what I see:
Jan 25, 2021, 8:36:54 PM Debug [ 'Sheet3', 'EDIT' ]
@Jeff_Hager@Darren_Murphy The above code I sent is placed in Script Editor in Google sheet itself and not sent through glide. Yes I am placing a value in a cell through script. But I want this value on a single cell and not after that …
I tried onEdit as well that executed on each edit in a sheet but I want only when New Row is added via Glide app … I tried set column Action, but it is not working and somebody already reported a bug for that (Add row & Set column) Add row places a row in Glide table, but did not add row in Google sheet…
@Nitesh_Aggarwal this is most likely the reason why your script is not executing. (Or more correctly, it probably is executing, but it isn’t getting past that conditional)
@Darren_Murphy@Jeff_HagerMy simple use case is … I have Blank sheet (with no rows) and 2 columns ( A & B) … I just want to set value of A via form (user input) and add Default value of 100 to column B (without asking to user) … and I need this only for the first row …
And yes obviously when form is submitted I need only 1 row to be created in Google sheet as well as in Glide Sheet …
Um, why do you need a script for this?
Why not use a Set Columns action when the user submits the form?
If you only need it for the first row, you can create a rollup that counts the number of rows, and only do the Set Columns action if that count = 1.
Alright, getting back to your script, here is a version that will work:
function on_change(event) {
var sheet = event.source.getActiveSheet();
var sheetname = sheet.getName();
if (sheetname == 'Sheet1') {
sheet.getRange(2,2).setValue(100);
}
}
Note that will reset that cell to 100 every time there is a change to that sheet. I’m not sure if that’s exactly what you want.
function on_change(event) {
var sheet = event.source.getActiveSheet();
var sheetname = sheet.getName();
if (sheetname == 'Sheet1') {
var check = sheet.getRange(2, 2).getValue();
if (!check) {
sheet.getRange(2, 2).setValue(100);
}
}
}
That will only set the value in B2 if it is empty.