JS/Apps Script: How do I map nested keys?

Advertisements In the following Google Apps Script code, I want to write three keys to the sheet key_1,key_3.subkey and key_4[1].key. How do fix my code to show the subkey and second element of key_4 as well? function main() { const data = [{"key_1":10,"key_2":20,"key_3":{"subkey":30},"key_4":[{"key":41},{"key":42}]},{"key_1":40,"key_2":50,"key_3":{"subkey":60},"key_4":[{"key":43},{"key":44}]}]; const keys = ["key_1","key_3.subkey","key_4[1].key"]; print(data, keys); } function print(data, keys) { ss… Read More JS/Apps Script: How do I map nested keys?

How to preserve borders, merged cells & formula when using SetValue() function in AppScript?

Advertisements I have recently written a code that fetches a range of date & sets it on another sheet. It works fine, but the set data is a little hard to read because the table borders/alignment/formula are not preserved. Is there a way that this can be preserved? The script: function saved() { //Source link… Read More How to preserve borders, merged cells & formula when using SetValue() function in AppScript?

How to extract a username from an email address using Google App Script

Advertisements I’m using the following script to get the user’s email address: function getEmail() { var userEmail = Session.getActiveUser().getEmail() Logger.log(userEmail); } It logs something like this: username@domain.com I’d like to extract the username (everything to the left of @) and log it. >Solution : About It logs something like this: username@domain.com, when your showing script… Read More How to extract a username from an email address using Google App Script

How do I convert this textFinder to only return the email it finds in a specific column?

Advertisements I currently have a Spreadsheet table of employee details. The code below works fine as long as the email is unique (only one occurrence in the table’s column E). However, other user emails are also found in the supervisor/manager columns email, which results into the code below referencing that first email occurrence and thus… Read More How do I convert this textFinder to only return the email it finds in a specific column?

Resize multidirectional arrays JavaScript Google script

Advertisements I need to resize arrays by adding empty new columns and empty new rows. Ex newRows = 2 newCols = 3 (1s are just placeholder for any data) arr= [ [1,1,1,1], [1,1,1,1], [1,1,1,1], ]; To arr= [ [1,1,1,1,"","",""], [1,1,1,1,"","",""], [1,1,1,1,"","",""], ["","","","","","",""], ["","","","","","",""], ]; I can get the new empty cols but not the new… Read More Resize multidirectional arrays JavaScript Google script

How to replace part of a string using the slice method with an IF condition

Advertisements I have the following script which is required to remove characters in a string leaving only the characters which follow the ">" character. For example, "GOOD > WEEKEND". When the script runs the output should be "WEEKEND". As there is one space after ">" i’m using slice(v.indexOf(">")+2) The problem is everytime the script runs… Read More How to replace part of a string using the slice method with an IF condition

Turning single values and arrays into arrays including zeros as single value

Advertisements While I was searching for a good way to check if a function variable is an array or a single variable and then turn both into arrays for further processing, I came across this post. The answer provided by @VoteyDisciple var eventsArray = events ? [].concat(events) : []; works great for me until events… Read More Turning single values and arrays into arrays including zeros as single value

Turning single values and arrays into arrays including zeros as single value

Advertisements While I was searching for a good way to check if a function variable is an array or a single variable and then turn both into arrays for further processing, I came across this post. The answer provided by @VoteyDisciple var eventsArray = events ? [].concat(events) : []; works great for me until events… Read More Turning single values and arrays into arrays including zeros as single value