1

I am trying to upload data from an app to a Google Spreadsheet using the Google App Script but the webapp is not working. I have republished the app after the following state but it still does not work and I keep getting the error.

The script completed but did not return anything.

I have also made the permission changes for both the spreadsheet and the app.

WebApp Code

var ss = SpreadsheetApp.openByUrl("SpreadSheet Link");

var sheet = ss.getSheetByName('Items')

function doPost(e){
var action = e.parameter.action;

if(action == 'addItem'){
  return addItem(e);

}


}





function addItem(e){

var date =  new Date();

var rssi = e.parameter.RSSI;

var id  =  e.parameter.UUID; 

var time = e.parameter.TimestampCode;

var scanSetting = e.parameter.ScanSetting;

var advSetting = e.parameter.AdvertisementSetting;

sheet.appendRow([date,rssi, id,time,scanSetting, advSetting]);

   return ContentService.createTextOutput("Success").setMimeType(ContentService.MimeType.TEXT);



}

Android App Function

private void  addItemToSheet(String rssi, String uuid, long timeStamp) {

        final ProgressDialog loading = ProgressDialog.show(this,"Adding Item","Please wait");
        String rssiData = rssi;
        String uuidData;
        if(uuid == null){
            uuidData = "null";
        }
        else {
            uuidData = uuid;
        }
        String timeStampData = String.valueOf ( timeStamp );
        String scanSettingChosen = scanSetting;
        String advSettingChosen = advSetting;





        StringRequest stringRequest = new StringRequest( Request.Method.POST, "WebApp Link",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        loading.dismiss();

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                }
        ) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> parmas = new HashMap<> ();

                //here we pass params
                parmas.put("RSSI",rssiData);
                parmas.put("UUID",uuidData);
                parmas.put("TimestampCode",timeStampData);
                parmas.put("ScanSetting",scanSettingChosen);
                parmas.put("AdvertisementSetting",advSettingChosen);

                return parmas;
            }
        };

        int socketTimeOut = 120000;

        RetryPolicy retryPolicy = new DefaultRetryPolicy (socketTimeOut, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
        stringRequest.setRetryPolicy(retryPolicy);

        RequestQueue queue = Volley.newRequestQueue(this);

        queue.add(stringRequest);


    }
new name
  • 15,861
  • 19
  • 68
  • 114
Ravish Jha
  • 481
  • 3
  • 25
  • The above is an automated message sent on our behalf when we ask the community to link a question to one that we consider has an answer. Could you please clarify if the `doPost` trigger function actually reaches the `action == 'addItem'` clause? Also, please check the execution logs - do they show that the app completed successfully? Btw, when developing, you can directly request `/dev` endpoint instead of `/exec` - this way you won't have to redeploy until sure that updates work. It would also help if you added info on what is logged when you access `parameter.action` – Oleg Valter is with Ukraine Jun 12 '20 at 20:22
  • @Cooper - since its inclusion I feel compelled to explain that's not me inviting to the discussion :) Ravish, other than mentioned above, I also noticed that you never actually add query string parameters to the Web App url - you have to pass them as query string for them to be picked up – Oleg Valter is with Ukraine Jun 12 '20 at 20:37
  • 1
    Yeah I got that just a couple of hours ago, Thanks a ton! – Ravish Jha Jun 13 '20 at 06:27

0 Answers0