List help: how to input a list in a spreadsheet using appscript

I already know the basics of using “appscript to spreadsheet”, but I need the ability to input many rows in one click of a button, I have prepared a list as follows:

(2NA149 20 2 KARATAN Because Broke  
TA0810 15 2 BENGKOK Because Broke  
TA0830 20 2 KARATAN Because Broke )

maybe the first thing is how to make a list recognized by appscript.

use this script code, make into web app, set permission to use by anyone, get script url. prepare the list, then

function doGet(e) {
  try {
    const sheetName = e.parameter.sheet;
    const dataString = e.parameter.data;

    // Check if parameters are provided
    if (!sheetName || !dataString) {
      return ContentService.createTextOutput('Missing sheet name or data');
    }

    const rows = JSON.parse(decodeURIComponent(dataString));

    // Check if rows are valid
    if (!Array.isArray(rows) || rows.length === 0 || !Array.isArray(rows[0])) {
      return ContentService.createTextOutput('Invalid data format');
    }

    const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
    
    // Check if sheet exists
    if (!sheet) {
      return ContentService.createTextOutput('Sheet not found');
    }

    const lastRow = sheet.getLastRow();
    sheet.getRange(lastRow + 1, 1, rows.length, rows[0].length).setValues(rows);

    return ContentService.createTextOutput('Success');
  } catch (error) {
    return ContentService.createTextOutput('Error: ' + error.message);
  }
}

set blocks like this…

On button click

set web1 url to appsScript url?&sheet=SheetName&data=get global list
web1.get

but in the project setting don t forget to enable showListAsJson else this one wont work

thank you for your help I will try it soon, and come back with news about the problem :blush:

I want to ask how to correctly write a “list”, whether what I showed first is the correct writing of a list, and how to write a list that can be used to run the appscript “script” input to a spreadsheet of many rows in one click, which means the list must be in line-by-line format. sorry the writing confused you

minimum how much rows you want to add at once?

15 lines, but it could be more than that

so why you can’t use range query to insert more data like
Range from A1 to D15
it will insert givin data to
A1 B1 C1 D1



A15 B15 C15 D15

friends, how can I create a block to create a json like the following, can you show me please show it in your beautiful block

[
  {"item": "2NA149", "qty_ok": 20, "qty_ng": 2, "ket_ng": "KARATAN", "ket_problem": "Problem"},
  {"item": "TA0810", "qty_ok": 15, "qty_ng": 1, "ket_ng": "KARATAN", "ket_problem": "Problem"},
  {"item": "TA0830", "qty_ok": 20, "qty_ng": 2, "ket_ng": "BENGKOK", "ket_problem": "Problem"},
  {"item": "TA0840", "qty_ok": 15, "qty_ng": 4, "ket_ng": "BENGKOK", "ket_problem": "Problem"},
  {"item": "TA0850", "qty_ok": 15, "qty_ng": 3, "ket_ng": "BENGKOK", "ket_problem": "Problem"},
  {"item": "TA0820", "qty_ok": 10, "qty_ng": 3, "ket_ng": "KARATAN", "ket_problem": "Problem"}
]

You can use Dictionary block


Write “item” in the key box and value in the value box “2n233”

Thank you for your participation in helping me find a solution, but your answer is clear, what I want is a dictionary block technique to create a JSON format that matches what I showed above.

I have created it in JSON format as above. The next step is to send it to AppScript and process it, then the data will be input into the spreadsheet according to the dynamic form.

the above provided script is to send the datas as a list and not as json… By the way why do you want to make it as json? using this block (alike) you can make a list and send it to the script url. It will take care of the remaining

image

image

image

i am getting this error message what does it mean, this has me confused.

I’m still a beginner so I’m trying any method that can send multiple rows of data in one click, before that the user can select the data and edit the data, until it is finally sent to the spreadsheet at once based on the relevant rows with dynamic components (UI). so do you have any suggestions and please provide technical answers in the form of your genius block.

sending as a list is always very convenient method instead of making into json