0
votes

I have a spreedsheet, with a sheet feed by a Google Form. unfortunetly, I need special features, like conditional formatting, and data added by google form are added in a new line without format.

So, I did an other sheet, with the same columns, and I had to copy paste from the first one to the second one. I'd like this copy to be automated. So I tried to do it using Google App Script. But it seems like I did something wrong with the trigger.

Here is the code :

function creerTrigger()
{
  ScriptApp.newTrigger('deplacerCommande').forSpreadsheet("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").onFormSubmit().create();
}

function deplacerCommande(e)
{
  var id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  var feuille = SpreadsheetApp.openById(id).getSheetByName("Commande");
  feuille.appendRow(e.namedValues);
}

When I run deplacerCommande() from Google App Script, the messageBox is displayed, but not when a form is submitted, so I don't think the trigger works.

Yes, I created my trigger. I did it by running the function creerTrigger() from Google App Script. I also tried deleting it, then changing the version, then recreating it, because I read it can solve the problem, but it didn't.

list of trigger

It's in French, but I'll translate the value for you : deplacerCommande is the name of the function called by the trigger. the second value means From the spreedsheet. the third means sending Form

1
I would guess that the error is related to trying to display a message box in this context. Triggers will run even when no one has the spreadsheet open so there would be no one there to see the msgbox. - Cooper
You can also set the notification on the trigger to immediate so that you get an error message sent to you fairly soon after the error occurs. - Cooper
You may wish to check to see if the trigger already exists before you create another. - Cooper
I confirm the first comment, triggers can not show anything in the UI, browser class is included in this restriction. - Serge insas
Thanks for your tips. the message box was just for trying to understand why it doesn't work, or if it really triggers. It already didn't worked before I added the messageBox. I checked, there is no other triggers. But I'll set notification on it, and will send an other form to see if it triggers or not. - Stef

1 Answers

0
votes

The solution was simple. The trigger triggered, but the appendRow function raised an Exception because namedValue is an object, not an arrow. using e.values instead of e.namedvalues solved the problem!