onformsubmit trigger does not work when using web app forms

163 views
Skip to first unread message

シナガアディプトラ

unread,
Mar 9, 2023, 11:36:32 PM3/9/23
to Google Apps Script Community
I'm trying to create a form using web app scripts and the data is stored in gsheets. I made a scrit for automatic notification if there is new data to chatwork apps. when using google forms it works fine but when using web app forms it doesn't work trigger on form submit. any suggestions?

cbmserv...@gmail.com

unread,
Mar 9, 2023, 11:39:25 PM3/9/23
to google-apps-sc...@googlegroups.com

You don’t need a trigger if its your own webapp, just use the webapp code to do what functions you wanted the sheet trigger to do.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/1438fef5-8dd8-42cf-8a9f-13f95fd67b99n%40googlegroups.com.

シナガアディプトラ

unread,
Mar 10, 2023, 12:13:03 AM3/10/23
to Google Apps Script Community

this is the script for the trigger. where should I put this function? in the web app form code so that it can be run when there is new data in the sheets.

function autoReply() {
 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data");
 var row = sheet.getLastRow();
  var invoice = sheet.getRange(row, 2).getValue();
        var responsible = sheet.getRange(row, 9).getValue();


 var notify_body
  = "[toall] [info][title]new data。 (gogo)[/title]\n"
    + "code order : " + invoice + "\n"
        + "in charge : " + responsible + "\n"
    +"----------------------------------------\n"  [/info]";


 var roomId = "roomID"
 var client = ChatWorkClient.factory({token: "0c0219265533a8b8e71d160bda27ec3f"});
 client.sendMessage({room_id: roomId, body: notify_body});
}

cbmserv...@gmail.com

unread,
Mar 10, 2023, 12:14:15 AM3/10/23
to google-apps-sc...@googlegroups.com

Show us your webapp code and will let you know.

シナガアディプトラ

unread,
Mar 10, 2023, 12:22:43 AM3/10/23
to Google Apps Script Community
I have a web app form with 2 files.
index.html
https://codeshare.io/mpbnw4

code.gs
https://codeshare.io/dwQzqR

if deployed it will generate a web app form like google form. thanks if you want to help me.

cbmserv...@gmail.com

unread,
Mar 10, 2023, 12:32:48 AM3/10/23
to google-apps-sc...@googlegroups.com

Ok from what I can see, your function addRows is the one that injects the data into the spreadsheet.

 

function addRows(obj){

  let sheetName = ss.getSheetByName('Data');

var rndNum= getRndNumber(1, 999);

var id = ('000' + rndNum).slice(-3);

let uid = 'FUJI' + id;

 

So what you need to do is inside addRows, make a call to your function inside the spreadsheet to send the notification. To do that, get the script Id of the script contained in the spreadsheet, then add that script as a Library to your webapp.

 

Once you have added that script as a library to your webapp (you can call your autoreply function directly at the bottom of addRows function.

 

Calling a library function is done this way:

 

   libraryName.autoReply();

 

libraryName is whatever Google name you gave your script, but you can also change it when you add the library

 

Hope that helps.

nagastar

unread,
Mar 10, 2023, 12:43:42 AM3/10/23
to Google Apps Script Community
thankyou to help me sir..
but how to do this sir, can u guide me or edit in my code share?

 " To do that, get the script Id of the script contained in the spreadsheet, then add that script as a Library to your webapp. "

cbmserv...@gmail.com

unread,
Mar 10, 2023, 12:48:03 AM3/10/23
to google-apps-sc...@googlegroups.com

Not sure how to get the script id from code share. That is something you get from the Google AppsScript Editor.

Click on the setting button (gear) and then look for the ID shown in below:

 

image001.png

nagastar

unread,
Mar 10, 2023, 12:56:09 AM3/10/23
to Google Apps Script Community
I got the script id. how do I create the library?

Here is the script id;
1iAEU7jBmb5eUS-K4FCtvQJ37sk3R7q-iMBgUgbNOqI9Ly9ymsPheM4X

I ask you to edit it in code share to create a library and call the autoreplay function sir. I'm a beginner here. 

cbmserv...@gmail.com

unread,
Mar 10, 2023, 1:00:26 AM3/10/23
to google-apps-sc...@googlegroups.com

Check attached screenshot. Click on the + beside library (this needs to be done from where your webapp is being edited. After you click the + enter the script Id and click lookup, it should find it, then you can type in the name of the library you want to use in the coding and then click add.

 

 

After you have added the library, you can then add that one line of code at bottom of addRows () but before the return statement!!

image001.png

nagastar

unread,
Mar 10, 2023, 1:11:04 AM3/10/23
to Google Apps Script Community
I have added a script id to the library with the name ordersystemrelease.
I added the script ordersystemrelease.autoReply
I added the autoreply fucntion script underneath. but it's not running yet. is there something wrong?
ddsds.PNG

cbmserv...@gmail.com

unread,
Mar 10, 2023, 1:13:50 AM3/10/23
to google-apps-sc...@googlegroups.com

Yes, that is not how it is to be called.

 

Just add this: 

 

   ordersystemrelease.autoReply();

 

inside the addRows function before the return true; statement.

 

Also, make sure you republish the webapp for this to take effect.

 

From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> On Behalf Of nagastar
Sent: Thursday, March 9, 2023 10:11 PM
To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: Re: [Apps-Script] onformsubmit trigger does not work when using web app forms

 

I have added a script id to the library with the name ordersystemrelease.


I added the script ordersystemrelease.autoReply
I added the autoreply fucntion script underneath. but it's not running yet. is there something wrong?

image001.png

nagastar

unread,
Mar 10, 2023, 1:26:08 AM3/10/23
to Google Apps Script Community
It's working fine now.
Thank you sir for saving me. :)

cbmserv...@gmail.com

unread,
Mar 10, 2023, 1:27:10 AM3/10/23
to google-apps-sc...@googlegroups.com

nagastar

unread,
Mar 17, 2023, 3:59:56 AM3/17/23
to Google Apps Script Community

CBMServices Web

unread,
Mar 17, 2023, 12:41:06 PM3/17/23
to google-apps-sc...@googlegroups.com
I am not familiar with this chat app. However you can not use the simple onEdit trigger to do this.

Simple triggers are only allowed to make changes to the spreadsheet they are in. No outside services permitted.

Change the function name from onEdit to something else and then add a trigger to call this function when the spreadsheet is edited. (This is called an installable trigger).

Note: have not looked at your code as am not familiar with the chat program.


nagastar

unread,
Mar 17, 2023, 7:58:30 PM3/17/23
to Google Apps Script Community
I just want to run this function if in column J the checkbox is checked then in column E it will send data according to the row checkbox that is checked in column J.
how to create the correct condition if the checkbox is checked?

function autoReply() {
 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet");
 var row = sheet.getLastRow();
  var question = sheet.getRange(row, 5).getValue();
 //[info][/info]
 //[title][/title]
 var notify_body
  = "[info][title]this question has been answered[/title]\n"
    + "question : " + question + "\n"
    +"----------------------------------------\n" [/info]";

 var roomId = "200385145"//

 var client = ChatWorkClient.factory({token: "0c0219265533a8b8e71d160bda27ec3f"});
 client.sendMessage({room_id: roomId, body: notify_body});
}
Reply all
Reply to author
Forward
0 new messages