An issue while updating date recorded on the google sheet

an issue while updating date recorded on the google sheet


//UPDATE SINGLE RECORD
else if (e.parameter.func == "Update") {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0];
var data = [ [ e.parameter.name, e.parameter.id ] ];
sh.getRange("B"+(parseInt(e.parameter.id)+1)+":C"+(parseInt(e.parameter.id)+1)).setValues(data);
return ContentService.createTextOutput("Success");
}

getting that error
image

If your update has worked on the apps script and spreadsheet then your responseContent = "Success"

Obviously you cannot convert this to a list

image

When you get such an error you should be using Do It to see what is happening, or putting your responseContent to a label to see what is coming back. Basic debugging, and quicker than having to keep asking questions.

We have been talking about that already a few times in one of your other threads

Taifun

you have confused with GET request, Make sure Are you using only one GET request or multiple.? If multiple then in the web request you cannot handle like this.

Every Action words you should use one if condition. As per your block, update action request will throw only Success as a text output. In such case how can you make list items?

Here are by blocks lets figure it out

image
// UPDATE SINGLE RECORD
else if (e.parameter.func == "Update") {
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName("Sheet1");
var data = [
[
e.parameter.name,
e.parameter.cusid,
e.parameter.address,
e.parameter.accnum,
e.parameter.pymmthd,
e.parameter.memb,
e.parameter.cusdate,
e.parameter.cusday
]
];
sh.getRange("B" + (parseInt(e.parameter.id) + 1) + ":I" + (parseInt(e.parameter.id) + 1)).setValues(data);
return ContentService.createTextOutput("Success");
}
}

Based upon what you are sending from your app the above should be changed to:

var ss = SpreadsheetApp.openById(e.parameter.ID);
var sh = ss.getSheetByName(e.parameter.SH);

Everything else looks OK...

Depending on the content of your textboxes (is it in Arabic/Persian etc.), you may need to use the Web component's UriEncode block on the texbox.text...

i just changed it but didnt work as well
// UPDATE SINGLE RECORD

else if (e.parameter.func == "Update") {

var ss = SpreadsheetApp.openById(e.parameter.ID);

var sh = ss.getSheetByName(e.parameter.SH);

var data = [

[

e.parameter.name,

e.parameter.cusid,

e.parameter.address,

e.parameter.accnum,

e.parameter.pymmthd,

e.parameter.memb,

e.parameter.date,

e.parameter.day

]

];

sh.getRange("B" + (parseInt(e.parameter.id) + 1) + ":I" + (parseInt(e.parameter.id) + 1)).setValues(data);

return ContentService.createTextOutput("Success");

}

}

Try with the UriEncode block on your day_box.txt

image

didnt work as well
here us a sample file i just created lets check it please
test201.aia (6.8 KB)

If something does not work it might help to read the error message coming back in the GotText event

Try to uri encode also the date

Taifun

the issue is with the script code as i tried only two columns before and didnt work so lets send me a working update script to try it
image

Update your script to a new version

If that still doesn't work, show your full script.

function ManageSheet(e) {
  // READ ALL RECORDS
  if (e.parameter.func === "ReadAll") {
    var sheetId = e.parameter.sheetId; // Get the sheet ID from the request
    var ss = SpreadsheetApp.openById(sheetId); // Open the sheet by ID
    var sh = ss.getSheets()[0];  // Assumes you're working with the first sheet
    
    // Get all data in the sheet
    var data = sh.getDataRange().getValues();
    
    // Return the data as JSON for ListView
    return ContentService.createTextOutput(JSON.stringify(data))
          .setMimeType(ContentService.MimeType.JSON);
  }

  else if (e.parameter.func == "Delete") {
    var record = e.parameter.id;
    var sheetId = e.parameter.sheetId; // Get the sheet ID from the request
    var ss = SpreadsheetApp.openById(sheetId); // Open the sheet by ID
    var sh = ss.getSheets()[0]; // Assumes you're working with the first sheet
    sh.deleteRow(parseInt(record) + 1);
    return ContentService.createTextOutput("Success");
  }

  // UPDATE SINGLE RECORD
else if (e.parameter.func == "Update") {
var ss = SpreadsheetApp.openById(e.parameter.ID);
var sh = ss.getSheetByName(e.parameter.SH);
var data = [
[
e.parameter.name,
e.parameter.cusid,
e.parameter.address,
e.parameter.accnum,
e.parameter.pymmthd,
e.parameter.memb,
e.parameter.date,
e.parameter.day
]
];
sh.getRange("B" + (parseInt(e.parameter.id) + 1) + ":I" + (parseInt(e.parameter.id) + 1)).setValues(data);
return ContentService.createTextOutput("Success");
}
}

ManageSheet should be doGet

function doGet(e) {

Re-deploy your script to a new version after making this change

and your script normalised for all three functions...

function doGet(e) {

    var ss = SpreadsheetApp.openById(e.parameter.ID); // Open the sheet by ID
    var sh = ss.getSheetByName(e.parameter.SH);

  // READ ALL RECORDS
  if (e.parameter.func == "ReadAll") {
    var data = sh.getDataRange().getValues();
    return ContentService.createTextOutput(JSON.stringify(data))
          .setMimeType(ContentService.MimeType.JSON);
  }
  // Delete single record
  else if (e.parameter.func == "Delete") {
    var record = e.parameter.id;
    sh.deleteRow(parseInt(record) + 1);
    return ContentService.createTextOutput("Success");
  }
  // UPDATE SINGLE RECORD
  else if (e.parameter.func == "Update") {
    var data = [
	[
	e.parameter.name,
	e.parameter.cusid,
	e.parameter.address,
	e.parameter.accnum,
	e.parameter.pymmthd,
	e.parameter.memb,
	e.parameter.date,
	e.parameter.day
	]
    ];
    sh.getRange("B" + (parseInt(e.parameter.id) + 1) + ":I" + (parseInt(e.parameter.id) + 1 )).setValues(data);
    return ContentService.createTextOutput("Success");
  }
}

now provided him with doPost code , also the sheet contains anyone editor option and many users are mishandled it so the deploy is not function properly. His script code doesnot contain doGet(e) too. now everything fixed