Skip to content
Advertisement

Row is always returning 1 – Google Scripts

I am trying to display an HTML page with values from the spreadsheet. I click on my Generate HTML page link and it redirects to the HTML page I created. It displays correctly except that the script always gets values from the first row. I am under the impression that the doGet() function does not accept rows? What could it be?

Code.gs

JavaScript

agent-listing.html

JavaScript

openUrl.html

JavaScript

Advertisement

Answer

Here’s how I got it two work to pick up the current spreadsheet row and sheet. When I launch the dialog I use getScriptUrl() to get the current scriptApp.getService().getUrl() and to that I also add row and sheet name as query parameters to the url. I was planning on using them in the doGet() but in this version I decided to use cacheservice to store them for about 30 seconds which is more than enough time to launch ah3 which is like your agent listing and the dg() function uses them the get the active sheet and the current row.

I just tried it with doGet(e) and dg(e) using e.parameter.name and e.parameter.row to pass the row and sheet name so that the correct data could be displayed this also negates the need to call google.script.run.dg() in the ‘ah2.html’ file which is similar to your agent-listing.html.

My ‘ah3.html’ is similar to your ‘openURL.html’

JavaScript

My ‘ah3.html’ is similar to your ‘agent-list.html’

JavaScript

My ag3.gs is similar to your google script code

JavaScript

This is the version that uses the webapp querystring with name and row append to the url.

ag3.gs:

JavaScript

ah2.html:

JavaScript

ah3.html:

JavaScript

And I just tested this version and it’s getting the data correctly now that I modified the fetchSpreadsheetValues() function. The version above is probably still incorrect because I didn’t modify that function up there.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement