Importfeed function not loading RSS feed entries sometimes - google-apps-script

I have been using this sheet and many similar sheets for a long time but I have been facing this issue in many of the sheets. After a few days, the "importfeed" function stops loading the values on to the sheet. When I make a copy of the sheet (new spreadsheet), it instantly shows the values on the new sheet. It is a solution I do not want to use as I am using the script at different places and in that case I will have to change the script id everywhere. Please find the screenshot of the issue attached to this question below:
FYI, I am using a code to refresh the "importfeed" function every minute to get latest data. Any help would be great. Thanks

Related

How to solve the limitation of IMPORTRANGE formula in google sheet?

I have 50 google sheet files for 50 students. They need to key in their answers in their own google sheet file when they are asked to do so. I have a main google sheet to consolidate their data by using IMPORTRANGE formula. This is my formula:
=QUERY({IMPORTRANGE(...);IMPORTRANGE(...);IMPORTRANGE(...);...},"Select * where Col1 is not null")
I will have 50 IMPORTRANGE in the formula. So as expected, the main google sheet is very lag when the 50 students start to key in their answers at the same time. Sometimes, the formula will show #Value when all the students started to answer the questions at their own google sheet file. I need to keep refreshing the main google sheet so that the data will come out, but it will disappear again in a short while then I need to refresh it again (although it will settle down once most of the students finished answering the questions).
I know that using IMPORTRANGE is really not an efficient way to consolidate their answers in main google sheet file but I don't have other better way.
I tried to write a script so that they can send in their data by clicking the button assigned with the script. However, all the students need to go through the authorization process when they run the script for the first time. They don't know how to proceed when they saw the authorization process (not very good in using computer).
May I know is there any ways or tricks that I can use to solve the IMPORTRANGE issue? Or there are some way to write the script where we are not required to go through the authorization process when we run the script for the first time?
Hope to get some advice and help on this as I couldn't find a better way from Google already. Any help will be greatly appreciated!
If I understood correctly what you are looking is that your spreadsheet show in real-time the data being entered simultaneously on 50 different spreadsheets. I'm afraid that Google Sheets is not the right tool for what you are trying to do the way that you are trying to do it. Basically you have two options : change it or use a different tool.
It's not a good idea to have and array of multiple IMPORTRANGE functions that are being edited simultaneously because while the official docs says that IMPORTRANGE functions are updated every 30 minutes when the source and the spreadsheet having formula are opened at the same time the import is done practically immediately and could happen multiple times during the recalculation making causing it to start over an over again.
Replacing the above array by script might help only if you are open to not have the destination spreadsheet updated on real time as scripts are slow.
Replacing the above array by a program that uses the Google Sheets API also might help only if you are open to not have the destination spreadsheet updated on real time as the spreadsheet refresh.
Regarding running a script without requiring authorization that is only possible when using simple triggers and / or removing all the scopes that require authorization to run. Please bear in mind that you might create installable triggers to run other using the authorization of the user who creates them.
Related
Combining multiple spreadsheets in one using IMPORTRANGE
Why do two users sometimes see different values from importrange?
Multiple IMPORTRANGE
Using that many IMPORTRANGE formulas is definitely a bad idea. What I'd suggest you to do:
keep a list of all your student spreadsheet in your main document
write a script that will browse through all of the spreadsheets from that list and copy/paste values into your main document
create a time based trigger that will run the script every X minutes (or hours), depending on how accurate you want the results to be
This is a simple solution, but efficient. Depending on the amount of data and number of students/spreadsheets you may consider other solutions (like writing a cloud function that will do the same as the script) but I think this will work for your use case

Recording any copies made of a google sheet

I would like to create a Google sheet that records any copies that have been made of another Google Sheet even when the user creates a copy by putting 'copy' into the URL (https://docs.google.com/spreadsheets/d/"spreadsheet-ID"/copy).
I have found a solution on the post: Track number of copies made from a google spreadsheet but this doesn't record copies made when changing the URL as the above example.
I would like to know the whole URL of the sheet preferably but just the Spreadhseet ID would still be enough for me.
Has anyone got any ideas how I can record all this data onto a spreadsheet please?
Basically you won't have access to see who is copying your sheet if you use the built-in Make Copy.
What you could do is integrate part of the question you have provided, while disabling the built-in sharing method. So the only way to copy your sheet could be through a custom function you can control and register every time it executes.

How do I speed up Sheet load times with a lot of importranges?

I've been promoted into developing & maintaining a Google Sheets database at work. I know very little about Google Sheets scripting & from asking around, and researching it's looking like GAS is probably the avenue that I need to start heading down.
So we have 3 Workbooks in Google Sheets; 2 contain large amounts of data, the other workbook provides a UI for our sales dpt. to access the data. I really wish I could share these with you, as describing them is difficult. In the UI workbook, separate pages are paired with sheets in the one database (lets call it database A).
A salesman will go to the UI sheet for the product he's selling a device for; the top section of the sheet allows him to select, essentially, a row from database A. After the selection is made, the rest of the sheet is populated with products we manufacture that work with the choice made in the top section; the products we make are stored in the other database ("B"). We have to have two databases, as we've earlier hit the cell-limit in sheets with the two databases combined.
On average each UI page has about 150 Importranges. Looking up done with Query.
Our problem is that this UI is getting pretty slow, initial load time makes it worthless for salesmen on the road, and annoying to the salesmen here in the office. The delay when making the initial selections (querying database A) is usable, but still much slower then we'd like. And we're not finished building UI pages.
I've seen online that most people recommend using Apps Script to replace importrange, but knowing nothing about Apps Script, I haven't been able to understand what is being done, or mainly how to take the apps script and actually put the data in the cells.
So I'd appreciate any help I could get in speeding this up.
First let me say that the Google Apps script documentation has improved greatly over the years and I find it pretty easy to use now. If you open up a code editor in Google Sheets and go to Help menu and select API reference then that links you up to just about everything you need to know. If you go to the Google Apps reference for spreadsheets and look at the SpreadsheetApp object you'll see that there's three commands to open up another Spreadsheet not a sheet but a Spreadsheet. You can do it by file, by id or by URL.
If you click on the Url command it will take you to an example like this:
// The code below opens a spreadsheet using its id and logs the name for it.
// Note that the spreadsheet is NOT physically opened on the client side.
// It is opened on the server only (for modification by the script).
var ss = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/abc1234567/edit');
Logger.log(ss.getName());
As it points out, it doesn't actually open the file on the client-side it just opens it up on the server. So it may be necessary for you to open them up manually at first just to get an idea of what they look like. Once you know how they are organized then you can use the open command to get a Spreadsheet Object and from it select a specific sheet and then a data range. Once you have a range then you can load an array like this.
var myArray = rng.getValues();
This will load the entire range in one fell swoop into a JavaScript array and of course it would be nice if you can filter out unwanted data from the array and then put it into your current sheet at a desired range. Note that the range sizes have to be exact matches and also please realize that ranges start from 1 and arrays start from 0 so that can cause you some grief. Also let me add a few caveats that I've run into.
If your dealing with a one row or one column range array then you have to get the array's in the correct form. I tried writing them here but the Stack Overflow text converter keeps messing them up so I'd recommend you go to my reference on that issue here.
If you've coded in JavaScript in the past I'm guessing that you'll have no problem coming up to speed with Google Apps Scripting with the new documentation and an occasional visit to Stack Overflow for a question or two. I've gotten some great answers here from other users. If you need a JavaScript reference here's one that I use.
You are probably best off using a WebApp served from Google Apps Script for the UI which I'd be happy to help with if you had some sample data. If you wanted to still use the sheets, then you could replace the importRanges with some Google Apps Script function that runs every 10 minutes or so to keep the UI sheet updated. It should speed up load times. Something like this would work for you:
function importSheetA() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var database = SpreadsheetApp.openByUrl("DATABASE_A_URL");
var dataToCopy = database.getSheetByName("DATABASE_A_SHEET_NAME").getDataRange().getValues();
var copyToSheet = ss.getSheetByName("UI_SHEET_NAME");
var copyData = copyToSheet.clearContents().getRange(1, 1, dataToCopy.length, dataToCopy[0].length).setValues(dataToCopy);
}

onEdit() stopped working?

So I have a Google sheet where, when a user enters a number of an item, it will output a description and price. I actually have 50 sheets (one for each state in the US) that are all almost exactly the same, but put out slightly different prices because state taxes vary from state to state.
I used onEdit() to have my sheet work and it was working fine until I changed where the source for information came from. Originally in my sheet, I had another page with all the item information so that a simple Vlookup could do most of the work except calculate the item's price (this is what my code was doing, using the info page that was in the sheet to calculate a price).
However, when an edit needs to be made to an item, I want to make it so that we only have to update one "master" sheet, and make a call by openByUrl(...) instead of going to all 50 sheets and copy pasting the information. I tried implementing this in a sheet, and now it doesn't work when I edit, but it does work when I manually go into script editor and press run. What gives?
EDIT: Here's the code requested.
function onEdit(d) {
itemPriceSetup();
}
// Runs the actual program.
function itemPriceSetup() {
// Grabs and stores the sheet where a customer places an item number and where the code will output the price to.
var orderSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Item Sale Doc");
var orderSheetArray = orderSheet.getSheetValues(1, 1, 34, 8);
// Grabs and stores the sheet that has the information on the item.
//***var infoSheet = SpreadsheetApp.openByUrl('link to info');
var infoSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet with info");
var infoSheetArray = infoSheet.getSheetValues(1, 1, infoSheet.getLastRow(), 10);
So the code with the three asterisks is what I want to use, but causes my the program to not work - that is, it onEdit() won't run (I have it commented out so the code will run - the line below it is the one I'm trying to replace). If I were to go through the debugger with the line un-commented, it actually works.
So I figured it out, but it's a bit strange. I didn't realize triggers for a script are found under resources, so I made put one straight in my script (I guess?). Either way, use the link and go to "Managing triggers manually" to read on how to do it.
https://developers.google.com/apps-script/guides/triggers/installable
I had the same problem onEdit(e) wasn't working. After trying out many different things disabling the new Apps Script V8 engine worked for me. To disable go to Script-menu Select Run and click disable the engine
Dissabling new Apps Script V8 engine
I hope this answer will helps many. I appreciate all of the help that I've received on StackOverflow.Thank you

Contacts not being collected from "Soccer Club Homepage" tutorial

I am new to google apps scripts and I am following the tutorial at https://developers.google.com/apps-script/articles/sites_tutorial and when I run the myContact function from step 1, no contact info is populated into my spreadsheet.
I have a group created called AZ_Pilot, and I have the myContact function set up as follows:
function myContact() {
var contacts = ContactsApp.findContactGroup("AZ_Pilot").getContacts();
SpreadsheetApp.getActiveRange().setValue(contacts[0].getPrimaryEmail());
}
The script runs with no errors, but nothing is updated within the spreadsheet. It's a bit embarrassing to be stumped at step 1, but here we are.
You are using getActiveRange() which is the range which is currently under selection in the spreadsheet. By default, it is the first cell in the spreadsheet. Maybe you have a different cell selected and therefore, the email might be written to a different cell. Try keeping the first cell in focus and running the function again.
Also, you haven't mentioned whether or not there are any contacts in the group you created :)
I was adding some additional logging information, and it just started working correctly with no change to the functional code. Not sure what happened there.