Shree Ram
Shree Ram

Reputation: 1

Google Script : multiple doPost in one project using MIT App inventor

is there a way where I can configure multiple buttons on the MIT app inventor screen to do post different data to google sheet. as I understand, there can only be a single doPost() method in google script.

so if I have different button on app, and I wish to call different function in google app script I do not know what to use. what different identifier can I use in MIT app inventor for different buttons.

thanks

Upvotes: 0

Views: 246

Answers (1)

Andras Sztrokay
Andras Sztrokay

Reputation: 113

You can make use of parameters for this by setting up your buttons in a way to direct to different urls, then retrieving the user's choice by making use of e.parameters in doGet(e).

HTML code

In your HTML template, you'd construct links / buttons to call your app using whatever parameter you want, eg.:

<!--The url comes from the template - see below-->

<a href="<?=url?>?functionOne=true">Function one</a>
<a href="<?=url?>?functionTwo=true">Function two</a>

Script

function doGet(e){
  var functionOne = e.parameter.functionOne;
  var functionTwo = e.parameter.functionTwo;
  
  //When functionOne is alled
  if (functionOne =="true"){

    //Do what you want here for function one
  }
  else if (functionTwo == "true"){

    //Do what you want here for function two
  }
  else {
  
  //This can be your base case here

  }

URL in template

You will want to include the script url before evaluating your template

template.url = ScriptApp.getService().getUrl()

Upvotes: 1

Related Questions