r/GoogleAppsScript • • May 26 '21

Question Average excluding Highest and Lowest values

6 Upvotes

Hello,

need to create a custom function (to be used in Google sheets) that calculates average excluding highest and lowest values included in any range

for example Range ( 1 2 3 4 5 6 ) function to exclude 1 and 6 and calculates average of ( 2 3 4 5 )

so I think it can conclude sum(range) - max(range) - min(range) /count(range) -2

Thanks in Advance :)


r/GoogleAppsScript • • May 04 '21

Question Help migrating from Excel to Sheets... specifically need help automatically hiding/unhiding rows.

6 Upvotes

Hi folks!

I was told this is the subreddit for my problem/questions.

First, yes I have googled this. I have looked at quite a few examples but for some reason it just isn't clicking for me with the Google App Scripts coding when coming from VBA.

I have a workbook in Excel that I built. I'm proud of it. Taught myself some basic VBA to get it to do things I needed done. We have a restaurant and I am building out our catering division more. I needed to streamline processes to make things more automated and such. I built this workbook that calculates information, outputs catering quotes, outputs catering contracts, etc. I have recently realized how damn powerful Google Sheets is as well as Google App Scripts. I want to move this all out of Excel and into the Google-sphere.

I am struggling with one specific piece right now. How to hide and unhide rows in a sheet based on whether the information in a specific cell in the row is populated.

At the suggestion of another user, I threw together a small example Google Sheet for people to reference and maybe help me.

The sheet is here.

Also, I had created a small video of a screen recording to show what my excel spreadsheet does so you can see more clearly what I want to do when I move this excel workbook over to google sheets.

This is the video. It's only like 45 seconds.

In my sample Google Sheet, I want to enter quantities into the "Amount" column of the 'Calc' sheet. You will see when you do that it auto-populates that info over into the 'Output' sheet.

I used the 'Output' sheet to extract a PDF Catering Quote for the customer, so I only want to see the rows that have quantities in them and want rows of items with 0 quantities to remain hidden unless a quantity greater than 0.5 is entered for that item in the 'Calc' sheet.

I kind of show that process in the Excel workbook in the video I linked above as well.

Also, not sure if you are comfortable with VBA, but here is my code for the 'Output' sheet in Excel. It's pretty logical to follow, I think. Learned VBA on the fly to get that going. I have a lot of other spots in my Excel workbook that utilize the hiding/unhiding of rows but I feel like if I can get it nailed down in this one sheet I can figure it out with the rest of them, hopefully.

Thanks for any ideas and help!


r/GoogleAppsScript • • Apr 18 '21

Question Sheets expert but new to AppScript

6 Upvotes

Hello,

I’m a veteran sheets user who just wrote a basic AppScript. I’m going to start teaching myself AppScript as the first coding language. After this I am going to learn more languages. Do you have any advice on how to get started?


r/GoogleAppsScript • • Apr 04 '21

Guide Generate URLs to insert sheet ranges into Google Sites

6 Upvotes

Was working on a quick project to publish data tables and charts from google sheets into a website generated by google sites.

The functionality for inserting charts is trivial and built-in, but inserting data ranges is not that trivial.

So I wrote this script. If you have a Named Range in a sheet, it generates an url that you can insert into google sites using their embed tool.

On any cell of the same sheet as the named range, you can put =url() to get the address of the range, or =rangeloc() to get a reminder of the actual range defined.

If you have several named ranges, the first one is url() or url(0), the second one url(1) and so on. Same arguments for the rangeloc function.

Hope it helps someone.

function rangeloc(n = 0) {
var namedRanges = SpreadsheetApp.getActiveSheet().getNamedRanges();
return namedRanges[n].getRange().getA1Notation();
};

function url(n = 0){
var spr = SpreadsheetApp.getActiveSpreadsheet().getId();
var sht = SpreadsheetApp.getActiveSheet().getSheetId();
var namedRanges = SpreadsheetApp.getActiveSheet().getNamedRanges();
var range = namedRanges[n].getName();
return "https://docs.google.com/spreadsheets/d/" + spr +'/htmlembed/sheet?gid=' + sht + '&range=' + range;
};

r/GoogleAppsScript • • Apr 01 '21

Question Getting a google app script reviewed?

6 Upvotes

Hi!

I have a google sheet with some app scripts associated to it. When I share it around, there's always the screen "This app isn't verified... go to ...unsafe".

I'm starting to read about getting the app verified but it's mainly about add-ons. I don't want to make it an add-on, neither an app. This is just a google sheet with app script.

Has anyone already been through this review process? If so, any tips? Thanks a lot!


r/GoogleAppsScript • • Mar 24 '21

Guide Alternate runtimes makes it easier to build Google Workspace Add-ons, now generally available

Thumbnail
workspaceupdates.googleblog.com
6 Upvotes

r/GoogleAppsScript • • Mar 17 '21

Resolved How to (reasonably) secure an API key?

6 Upvotes

Let's say I have a Sheets bound script that does an API request with UrlFetchApp.

Is there a way to have variables such as keys stored in like a library or something to keep them centralised as well as secret. Assuming that is the right way to do it, I understand there would be nothing stopping somebody from changing the code to Logger.log(key) for example but that is an acceptable risk.

What is a reasonably secure best practice way to keep keys hidden? I have in my head that it would be possible to have a separate script that can be referenced with as a library and that way also have the benefit of only needing to update the key once.


r/GoogleAppsScript • • Mar 12 '21

Resolved Code to change text color and remove underlining

6 Upvotes

Hi, i want to change the text color of a cell to black and also remove the underlining under the text.

How would the code look like? Can't seem to find it

EDIT:

I found an easy solution.

I just recorded a macro while doing these things manually, and then looked at the code.
Apparently I just forgot to add two apostrophes.

The code is: spreadsheetapp.getactive().getactivecell().setFontColor('#000000').setFontLine('none');


r/GoogleAppsScript • • Feb 27 '21

Question Connecting a google form to a Python code

6 Upvotes

So, I’m working on this project, that consist on a culinary recipes recommender system. Basically, I would like to send the recommended recipe link on a google form, so I can get the feedback. The problem is that the link to be sent -and some other stuff - are generated on a python code. Does anybody knows how to connect this two-the link generated from the python code to the app script that creates the form?


r/GoogleAppsScript • • Feb 25 '21

Question Questions re new IDE

6 Upvotes
  • How do you view script properties in the new IDE?

  • How do you search for a string across all the .GS files in a project? (CTL+F searches only the current .GS file and you have to manually switch to each one in turn to search them. )

Suggestions welcome!


r/GoogleAppsScript • • Feb 07 '21

Question How do big corporations deal with the quotas/limitations of Apps Script?

6 Upvotes

As per the current quotas for workspace accounts (link):

"Triggers total runtime" is limited to 6 hours a day.

I assume that this is the cumulative runtime of all the scripts of a particular workspace accounts.

If so, then it's not that difficult to hit this limit. That's 3600 seconds per day. If you have 20 users each running an automated script that takes 10 seconds and runs every hour, you're already at 4800 seconds.

How do you deal with this? Is this just a hard limit? Or am I misunderstanding the quotas?

Edit: thanks for the replies. I guess I'm just gonna test this myself by creating a sheet, and run a script every minute of the day, that takes a couple of seconds and writes the runtime of the script in a new row. By then, I'll now how this 6 hours/day is really enforced.

edit 2: I just now notice that my math is off by x6. 6 hours a day is not 3,600 seconds a day. It's 21,600 seconds.

I'm still gonna try to hit it with a dummy script that triggers every minute and make a follow up post :)

EDIT: UPDATE OF THIS POST HERE


r/GoogleAppsScript • • Jan 25 '21

Question Any way to keep /exec URL from changing between deployments?

6 Upvotes

Comment removed in protest of Reddit's API changes forcing third-party apps to shut down


r/GoogleAppsScript • • Jan 18 '21

Resolved Adding a Timestamp With Google Apps Script When Adding a Spreadsheet Row from Slack

6 Upvotes

I want to send information from Slack into a new row in a Google Sheet and include a timestamp indicating when that row was added.

Following Slack instructions on how to Send Information into a Google Sheet I have successfully added a row, but do not see how to send a timestamp along with it.

I found a Google Apps script from this Stackoverflow page to add a timestamp when a cell is edited:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    if( r.getColumn() == 1 ) { //checks the column
      var nextCell = r.offset(0, 1);
      if( nextCell.getValue() === '' ) //is empty?
        nextCell.setValue(new Date());
    }
  }
}

The script adds a timestamp when I manually enter data into the Google spreadsheet, but when I add a new row from Slack, no timestamp appears.

This Stackoverflow post is about a similar issue. It explains that there's a difference between pasting and editing, so I think my problem is related. But I still don't understand what exact changes to make in the script above, and I wasn't able to implement the corrected script on that page successfully either.

Can someone help me either

  • tweak the script above so it will work when I'm adding a row from Slack; or

  • figure out another way to send a timestamp from Slack as part of that row of data?


r/GoogleAppsScript • • Jan 18 '21

Resolved In order to get an add-on published officially, must I use Google’s CSS package?

6 Upvotes

I am developing a Google Sheet add-on that I would like to publish on the marketplace. I am using MaterializeCSS. Will Google reject me because I am not using the Google CSS Package?

For reference: https://developers.google.com/gsuite/marketplace/about-app-review


r/GoogleAppsScript • • Dec 23 '20

Question Can you confirm that GAS doesn't allow me to edit Data Studio reports?

6 Upvotes

I'm 99% sure that what I want to do is not possible, but would like to have it confirmed. Why? Because I'm not well versed in GAS, and am just starting to explore all the various ways I can use it for my SaaS idea.

Anyway.

I want to duplicate a Datastudio report, connect it to multiple sheets within a specific Google Sheet, and then give read-only access to specific users.

Ideally, this would be possible in GAS, but this is not possible (from what I can find).

Could you confirm this for me? :D

(if this IS in fact possible, I would love to know because that would make my life much easier.)


r/GoogleAppsScript • • Dec 17 '20

Resolved For anyone experiencing locked up Web app deployment or re-written Deployment ID

6 Upvotes

I've been debugging my old project for hours because it stopped working all of a sudden (CORS error and permission error at the same time, along with the said issue in the title). I'm really enjoying all this change lol Well, at least I resolved the last issue, so I thought I'd share this one in hope that whomever that got into this.

Ever since this new IDE got launched, the deployment UI has changed a little bit. If you go to the right top Deploy > Manage deployments, it shows the two separate list of deployments, one being Active and another for Archived ones. This isn't particularly new, but the oddity is that.. the deployment from each two editors, old and new, will be handled separately. What it means is that.. the "Active" deployment list may show two separate deployments

So, if you have deployed web app both on the old and the new editor, it will list both of them within the Active deployment lists, not the one, unless you archive either of them (which I'll explain later). In my case, the one from the old editor will be shown at the bottom, and it always gets precedence even if it weren't the latest deployment. This confused me into thinking that my new deployment were ignored and locked up. It is being listed as a new deployment, however the old deployment from the old editor is just inhibiting that from being published.

This isn't too much of a problem by itself, as you can edit one out by archiving, to have only one deployment listed in Active deployment. You can archive the Active deployment from the "Manage deployments" menu, so I archived the old deployment. Now I only see single deployment which is the newest one. You can do this by going to Deploy > Manage deployments, select the old deployment in the "Active" list, and then it shows the archive icon at the right top of the window. Click that and it asks for confirmation.

But the real annoyance here is that, the Deployment ID differs depending on which editor you used to deploy the code. This means that, for now at least, if you wanted to use the old Deployment ID, you shouldn't use the new editor to publish it, because it makes the old url unusable anymore.

For now, I'll use old editor to deploy codes because it's too messy and troublesome to change Deployment ID for all the WebApps I made to interact with this project.

---

I like the new IDE though. I think it's much more useful and have only a few complaints (one of them being it missing the feature to delete archived deployments - but I can always go back to the old editor to do this so I'm fine for now.) But, man this was so counter-intuitive. I reported this as an issue, so hopefully this will get organized better.

Hope this saves someone's time! Cheers!


r/GoogleAppsScript • • Dec 11 '20

Question Your thoughts on NEW IDE for Google Apps Script? will it be able to fulfill the need for a dedicated editor like VS Code?

6 Upvotes

Also, did you got the update?

63 votes, Dec 18 '20
13 Yes, Got the the Update?
50 No, Still waiting for it....

r/GoogleAppsScript • • Nov 14 '20

Question get user email in a web app run as me

6 Upvotes

Hi everyone,

for a bit of background, I work for a big company that wont allow me to make the tools to make my job faster so I am using a grey zone to be able to work on the company's data : using a google sheet as back end for a web app . it works fine for the most part. (as a side note: I am not a developer, I am an enthusiast so the questions are probably stupid, please bear with me :))

ok so my question : I would like to be able to retrieve the user's email when they visit my web app. I would use it as a way to pre fill certain fields and personalise the experience a bit. however considering I am using a google sheet as back end, I need to execute the app "as me" as far as I understand, if not I will need to give everyone access to the sheet and that's not desirable (I want users to add data in a controlled manner) nor practical. is that correct?

Is it also correct that I cannot retrieve the actual user's email if the web app runs 'as me'? if both are correct how do you guys do it? is there a way to get the user's email if the script is run as me? or is there a way to not need to give access to the backend spreadsheet to everyone in my company if I run the web app as the user?

thank you in advance !


r/GoogleAppsScript • • Nov 03 '20

Question Reddit in Google Apps Script

6 Upvotes

Hey all, hoping to get some help because I am not finding anything online about this. I am working on a way to schedule Reddit posts using Google Sheets, mostly because Apps Script is the language I tend to do the most coding in these days, and partly because I just think it would be cool. Anyways, I found snoowrap and have put the code into a script file in my Google Project, but can't seem to figure out how to call it. Apps Script doesn't allow for the "require" command, instead it just loads all scripts into one active space. So, when I write my own code, I keep getting a "snoowrap is undefined" error whenever I try to call a command.

If snoowrap isn't the way to go, I'm open to other suggestions as well. I am struggling to figure out the OAuth2 in Apps Script, so that's why I was trying to pull a library to help out.


r/GoogleAppsScript • • Nov 03 '20

Question Anyone actually measure the performance impact of using library imports?

6 Upvotes

Comment removed in protest of Reddit's API changes forcing third-party apps to shut down


r/GoogleAppsScript • • Sep 26 '20

Question Need to prevent GAS web app instances from colliding

6 Upvotes

I'm using Google Apps Script to create a web app for my Telegram bot. The web app is invoked by the bot via web hook.

My bot has an inline keyboard that you can see in action in GIF 1 below. Tapping the keyboard buttons you enter a code that appears on the screen.

My problem is when I tap the buttons a little faster, callback queries to the web app collide, which results in messed up entry. See GIF 2.

I've been racking my brain trying to figure out a way to prevent instances of the web app from collision, but I've had no luck so far.

I'm posting my code below. Please, help.

The way I see it is that every instance of the script needs more time to complete before the next one kicks in. I've tried using async/await and lockService to the best of my understanding. I've been advised to try and queue the queries, but sadly haven't been able to make it work.

function doPost(e){

var contents = JSON.parse(e.postData.contents);

var query_id = contents.callback_query.id;

var mes_id = contents.callback_query.message.message_id;

var userinput = contents.callback_query.data;

var message_now = contents.callback_query.message.text;

var inline_keyboard = contents.callback_query.message.reply_markup;

var message_upd = message_now + " " + userinput;

var keydata = {

method: "post",

payload: {

method: "editMessageText",

chat_id: String(chat_id),

message_id: mes_id,

text: message_upd ,

parse_mode: "HTML",

reply_markup: JSON.stringify(inline_keyboard)

}

}

UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/', keydata);

UrlFetchApp.fetch(url + "/answerCallbackQuery?callback_query_id=" + query_id);

}

GIF 1

GIF 2


r/GoogleAppsScript • • Sep 25 '20

Question Pull Google classroom information for domain.

6 Upvotes

Do any of you clever individuals have any code for GAS that will pull information about Google classroom into a sheet. Class name, pupil, assignment name, and then the status of that assignment for each pupil (completed, not done, handed in late or even their grade)?

Would love to be able to pull this into data studio for reporting for my school


r/GoogleAppsScript • • Sep 23 '20

Question High number of URLFetchApp Unexpected Errors

6 Upvotes

Anyone else having unusually high number of occurrences of "Unexpected Error" from URLFetchApp.fetch() over the past couple weeks? Still works like 95+% of the time, but bugs out randomly.

This is from scripts that have been running fine for years and seemingly affects any URL used.


r/GoogleAppsScript • • Sep 19 '20

Question Connecting Google Sheet via Apps Script to Google Cloud SQL Server

6 Upvotes

I am currently hosting a SQL Server (2017) in Google Cloud. I can connect from my home machine via SSMS to my cloud instance without issue. Obviously, I don't want to open this to users. As they're already doing their work in Google Sheets, I want the their experience to remain (mostly) the same.

Using Google Apps Script, I can NEVER establish a connection to the same instance. I followed this article. I understand that I need to use Jdbc.getConnection instead of getCloudSqlConnection . I also added the Apps Script IP ranges to my instance (I even found a 2nd article with two additional IP ranges that aren't included in the above article).

I'm using the Public IP for the connection as the instance name will result in a response that you need to use the cloud method.

Talking to others and reading posts some folks say to just use MySQL. As a test I created a MySQL instance as well and the root user is set to allow any host.

Regardless of Cloud Instance, Jdbc method, users, etc everything results in "Failed to establish database connection".

Thoughts or experience that have helped you overcome a similar situation?

Thanks!

Edit: I had the incorrect syntax for jdbc:sqlserver:// despite seeing it in other folks posts and projects. I had to use:

var user = 'userID'
var userPwd = 'userPwd'
var url = 'jdbc:sqlserver://publicIP;databaseName=dbName'

/**
* Create a new database within a Cloud SQL instance.
*/
function createTable()
{
var conn = Jdbc.getConnection(url, user, userPwd);
conn.createStatement().execute('create table test (id int)');
}

Also, I'm unsure how to update the post flair, if there's something for that..