Jamie Marshall
Jamie Marshall

Reputation: 2294

Need assistance with unfamiliar syntax, error - e is undefined - Google Apps Script(GAS)

I'm using a script exactly like the one on the tutorial here, https://developers.google.com/apps-script/reference/ui/file-upload

However, despite using the syntax I keep getting e is undefined in the statement:

var fileBlob = e.parameter.dsrFile;

I think that means my function doPost(e) is probably wrong somehow. Here is my entire script below.

// Create Menu to Locate .CSV
function doGet(e) {
  var app = UiApp.createApplication().setTitle("Upload CSV");
  var formContent = app.createVerticalPanel();
  formContent.add(app.createFileUpload().setName("dsrFile"));
  formContent.add(app.createSubmitButton("Start Upload"));
  var form = app.createFormPanel();
  form.add(formContent);
  app.add(form);
  return app;

}

// Upload .CSV file
function doPost(e)
{
   // data returned is a blob for FileUpload widget
   var fileBlob = e.parameter.dsrFile;
   var doc = DocsList.createFile(fileBlob);
 }

Upvotes: 0

Views: 741

Answers (2)

patt0
patt0

Reputation: 800

Your script should work perfectly. e is defined by Google Apps Script, not need to pass anything in particular is contains the fields of your form, in particular in this case the file you uploaded.

I would suspect you may be falling foul to the dev url vs publish url syndrome, where you are executing an old scrip rather that the code you are currently working on.

Be sure you script end with 'dev' and not 'exec'

https://script.google.com/a/macros/appsscripttesting.com/s/AKfyck...EY7qzA7m6hFCnyKqg/dev

Let me know if you are still getting the error after running it from the /dev url

Upvotes: 0

Lajos Arpad
Lajos Arpad

Reputation: 76424

e is undefined because you are not passing anything to doPost. You have to pass the needed object to doPost. Check where you call the function and what parameters do you pass to it if any. Even if you pass a parameter to that function, it holds undefined value. Make sure that you are passing the correct objects to your functions.

Upvotes: 1

Related Questions