How to split text to row using app script

116 views
Skip to first unread message

Mr Irsan

unread,
Mar 18, 2024, 2:26:21 AMMar 18
to Google Apps Script Community
I made a daily student attendance app using Kodular and a spreadsheet as a database. I connected the kodular to a spreadsheet using Appscript. The app worked well, but since I'm a newbie in app script I can only send the data to a spreadsheet as shown below
outputdata.jpeg
I need help splitting the text using commas as delimiters into a row. Here's my expectation:
expectedresult.jpeg

here's the script I use to call the data from the app, I'm still a newbie and I just know basic functions like this:

function doPost(e) { 
return ceksheet(e); 
function ceksheet(e){
var ss = SpreadsheetApp.getActive(); 
var sh = ss.getSheetByName(e.parameter.SH); 
//CREATE 
if (e.parameter.func == "Create") { 
var ts = e.parameter.TIMESTAMP; 
var user = e.parameter.USER; 
var tgl = e.parameter.TANGGAL; 
var kls = e.parameter.KELAS; 
var nama = e.parameter.NAMA; 
var ket = e.parameter.KETERANGAN; 
var data = false; 
var lr = sh.getLastRow(); for(var i=1;i<=lr;i++){ 
var data_ts = sh.getRange(i, 1).getValue(); 
if(data_ts==ts){ data=true; } } 
if (data){ var result= "ID Sudah ada"; }
else{ 
var rowData = sh.appendRow([ts,user,tgl,kls,nama,ket]); 
var result="Berhasil Input"; 
return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.TEXT); }

FYI, here's the image of the app
appresult.jpeg
As you can see in the blue box, I intended to compile the data as one label per component ( timestamp in one label, name in one label, etc) as I planned to split it using appscript, It's just not resolved yet. Kindly need your help to resolve this problem...

Radian Muqorrobin

unread,
Mar 29, 2024, 6:12:50 AMMar 29
to Google Apps Script Community
is this problem resolved?

admin hbco

unread,
Apr 6, 2024, 7:21:20 AMApr 6
to Google Apps Script Community

Hi,

It is possible to try this function (
appendRow)

Example:-

function doGet(request){
    // Open Google Sheet using ID
    var ss = SpreadsheetApp.openById("1PhMwkI8EUNBJQck7YJLcxf2rFf1B_Q9YRSPYuaBpc4w");
    var sheet = ss.getSheetByName("Orders");
    var result = {"status": "SUCCESS"};
 
    try{
        // Get all Parameters
        var ProductId = request.parameter.ProductId;
        var ProductName = request.parameter.ProductName;
        var Amount = request.parameter.Amount;
        var Price = request.parameter.Price;
        var ProductSize = request.parameter.ProductSize;
        var CustomerContactNumber = request.parameter.CustomerContactNumber;
        var CustomerEmail = request.parameter.CustomerEmail;
        var CustomerLocation = request.parameter.CustomerLocation;
        var PaymentStatus = request.parameter.PaymentStatus;
        var OrderStatus = request.parameter.OrderStatus;
     
        // Append (Insert) data on Google Sheet
        var rowData = sheet.appendRow([ProductId, ProductName, Amount, Price,ProductSize,CustomerContactNumber,CustomerEmail,CustomerLocation,PaymentStatus,OrderStatus]);  
       
    }catch(exc){
        // If error occurs, throw exception
        result = {"status": "FAILED", "message": exc};
    }

    // Return Result
    return ContentService
    .createTextOutput(JSON.stringify(result))
    .setMimeType(ContentService.MimeType.JSON);  
}



Best Regards,

   

Basel El-Habil

Google Developer Groups - Gaza Organizer

Mob: (+972) -562-323008

E-mail: basel...@gmail.com

admin hbco

unread,
Apr 6, 2024, 12:20:55 PMApr 6
to google-apps-sc...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/07cc18db-05ef-4f24-998f-0d4dd5f03e8an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages