Issue with character encoding when sending data to Google Sheets

While storing data to Google Sheet, Turkish characters are not appearing in the cell.



Here is my script

function doGet(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries");

  addUser(e, sheet);
}

function doPost(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries"); 

  addUser(e, sheet);
}

function addUser(e, sheet) {
  
  var description = e.parameter.description; 
  var hotel = e.parameter.hotel;

  

  var lastRow = sheet.getLastRow();
  sheet.getRange(lastRow + 1, 3).setValue(description); // Column C
  sheet.getRange(lastRow + 1, 4).setValue(hotel); // Column D
}

Try the uriEncode block on your textbox.texts

1 Like

working thank you so much!

1 Like

I would like to make Autoincrement with sort Last in First. How do I do it with Apps Script?

function doGet(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries");

  addUser(e, sheet);
}

function doPost(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries"); 

  addUser(e, sheet);
}

function addUser(e, sheet) {
  var description = e.parameter.description; 
  var hotel = e.parameter.hotel;
  var username = e.parameter.username;
  var position = e.parameter.position;
  var status = e.parameter.status;

  // Find the last row
  var lastRow = sheet.getLastRow();

  // Get the value from the last row's first column (Column A) and increment it by 1
  var id = sheet.getRange(lastRow, 1).getValue();
  if (isNaN(id)) {
    id = 0;
  }
  id++;

  // Get the current date and time
  var date = new Date();
  var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yyyy HH:mm:ss");

  // Append the new row with the incremented ID, date, description, hotel, username, position, and status
  sheet.appendRow([id, formattedDate, description, hotel, username, position, status]);
}

You can test your script, or parts of it, using a function in your apps script project, running it directly, you can return outputs to console.log() and this will show up in the execution area.

Yes, you won't be able to run the entire script, as it is expecting parameters.

You are trying to set an incremented id, so just create a function that does this part, adding parameters as required.

Something like this:

function addId() {

var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries"); 

// Find the last row
  var lastRow = sheet.getLastRow();

  // Get the value from the last row's first column (Column A) and increment it by 1
  var id = sheet.getRange(lastRow, 1).getValue();
  if (isNaN(id)) {
    id = 0;
  }
  id++;

// Get the current date and time
  var date = new Date();
  var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yyyy HH:mm:ss");

  // Append the new row with the incremented ID, date, description, hotel, username, position, and status
  sheet.appendRow([id, formattedDate, 'descrip', 'hotel', 'username', 'position', 'status']);

}

While using this code: its adding autoincrement but I need to sort Last in First

function doGet(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries");

  addUser(e, sheet);
}

function doPost(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries"); 

  addUser(e, sheet);
}

function addUser(e, sheet) {
  var description = e.parameter.description; 
  var hotel = e.parameter.hotel;
  var username = e.parameter.username;
  var position = e.parameter.position;
  var status = e.parameter.status;

  // Find the last row
  var lastRow = sheet.getLastRow();

  // Get the value from the last row's first column (Column A) and increment it by 1
  var id = sheet.getRange(lastRow, 1).getValue();
  if (isNaN(id)) {
    id = 0;
  }
  id++;

  // Get the current date and time
  var date = new Date();
  var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yyyy HH:mm:ss");

  // Append the new row with the incremented ID, date, description, hotel, username, position, and status
  sheet.appendRow([id, formattedDate, description, hotel, username, position, status]);
}

While using this code Sort is working but issue coming with autoincrement

function doGet(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries");

  addUser(e, sheet);
}

function doPost(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries"); 

  addUser(e, sheet);
}

function addUser(e, sheet) {
  var description = e.parameter.description; 
  var hotel = e.parameter.hotel;
  var username = e.parameter.username;
  var position = e.parameter.position;
  var status = e.parameter.status;

  // Find the last row
  var lastRow = sheet.getLastRow();

  // Get the value from the last row's first column (Column A) and increment it by 1
  var id = sheet.getRange(lastRow, 1).getValue();
  if (isNaN(id)) {
    id = 0;
  }
  id++;

  // Get the current date and time
  var date = new Date();
  var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yyyy HH:mm:ss");

  // Append the new row with the incremented ID, date, description, hotel, username, position, and status
  sheet.appendRow([id, formattedDate, description, hotel, username, position, status]);

  // Sort the sheet by column B (Date) in descending order
  sortLastInFirstOut(sheet);
}

function sortLastInFirstOut(sheet) {
  var lastRow = sheet.getLastRow();
  if (lastRow > 1) {  // Ensure there's more than one row of data
    // Get the range of data excluding the header
    var range = sheet.getRange(2, 1, lastRow - 1, 7); // Columns A to G
    // Sort the data by the Date column (Column B) in descending order
    range.sort({column: 2, ascending: false});
  }
}


if I use date as a sort Last in first it's working

function doGet(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries");

  addUser(e, sheet);
}

function doPost(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries"); 

  addUser(e, sheet);
}

function addUser(e, sheet) {
  var description = e.parameter.description; 
  var hotel = e.parameter.hotel;
  var username = e.parameter.username;
  var position = e.parameter.position;
  var status = e.parameter.status;

  // Get the current date and time
  var date = new Date();
  var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yy HH:mm:ss");

  // Append the new row with the date, description, hotel, username, position, and status
  sheet.appendRow([formattedDate, description, hotel, username, position, status]);

  // Sort the sheet by column A (Date) in descending order
  sortLastInFirstOut(sheet);
}

function sortLastInFirstOut(sheet) {
  var lastRow = sheet.getLastRow();
  if (lastRow > 1) {  // Ensure there's more than one row of data
    // Get the range of data excluding the header
    var range = sheet.getRange(2, 1, lastRow - 1, sheet.getLastColumn()); // Adjust the number of columns if needed
    // Sort the data by the Date column (Column A) in descending order
    range.sort({column: 1, ascending: false});
  }
}

just i'm wondering can I use in future date with time and time like ID for example to find row and delete or for update? as we know date with time is a unique. or I need ID to specify row?

What do you think It's better to use google sheet or Google form?

To answer your first question, increment id and appendRow, then reverse sort the rows by id.

Then before doing it again sort to get the id numbers in order before incrementing again.

Actually, you could simply get the id value in the second row and add 1 for the increment, then appendrow then reverse sort again.

For example:

function addId() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Sheet1");
var lastId = sheet.getRange("A2").getValue();
  if (lastId == "") {
    lastId = 0;
  }
lastId++;
var date = new Date();
var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yyyy HH:mm:ss");
sheet.appendRow([lastId, formattedDate, 'descrip']);
sheet.getRange("A2:C").sort({column: 1, ascending: false});
}

image

1 Like
function doPost(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries"); 

  addUser(e, sheet);
}

function addUser(e, sheet) {
  var description = e.parameter.description; 
  var hotel = e.parameter.hotel;
  var username = e.parameter.username;
  var position = e.parameter.position;
  var status = e.parameter.status;

  var lastId = sheet.getRange("A2").getValue();
    if (lastId == "") {
    lastId = 0;
  }

  lastId++;

  // Get the current date and time
  var date = new Date();
  var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yy HH:mm:ss");

  // Append the new row with the date, description, hotel, username, position, and status
  sheet.appendRow([lastId, formattedDate, description, hotel, username, position, status]);
  sheet.getRange("A2:C").sort({column: 1, ascending: false});
}

Now it's working! Thank you so much!

function doPost(e) { 
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/108chmYw9A9ztvUNMiQneqG5adCSlI1Q5Yv6KAEFLvkw/edit?gid=1354188522#gid=1354188522");
  var sheet = ss.getSheetByName("Inquiries"); 

  addUser(e, sheet);
  addId(sheet);
}

function addUser(e, sheet) {
  var description = e.parameter.description; 
  var hotel = e.parameter.hotel;
  var username = e.parameter.username;
  var position = e.parameter.position;
  var status = e.parameter.status;

  // Get the current date and time
  var date = new Date();
  var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yy HH:mm:ss");

  // Append the new row with the date, description, hotel, username, position, and status
  sheet.appendRow(['', formattedDate, description, hotel, username, position, status]);
}

function addId(sheet) {
  var lastRow = sheet.getLastRow();
  var lastId = sheet.getRange("A2").getValue();
  if (lastId == "") {
    lastId = 0;
  }

  // Assign unique ID to the new row in column A
  lastId++;
  sheet.getRange(lastRow, 1).setValue(lastId);

  // Sort the sheet by column A (Date) in descending order
  sheet.getRange(2, 1, lastRow - 1, sheet.getLastColumn()).sort({column: 2, ascending: false});
}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.