0

I'm having a Google spreadsheet embedded in an (Episerver) page and the spreadsheet is editable. I also have a trigger onEdit in the sheet. When running that script 'onEdit' I'd like to get the info from current page using "document.getElementsByClassName().innerHTML" to get the context of the current situation, meaning fetching the username that is currently logged in that is displayed in the section within an element.

I'm getting the error 'document is not defined' and I got the reason. This is working just running the script as a pure javascript on the site. There is no success using GAS URLFetchApp since it not fetching the current page with the current user logged in. As I see it I have two possible options:

a) Is there anyway to use HTML DOM (document...) within Google Apps Script? b) Can I fetch current page instead of fetching a new URL in Google Apps Script?

JompaBoy
  • 23
  • 4

1 Answers1

0

A) I think your only option here is to us the XML service.
B) I don't believe so, as the script is self contained, and doesn't have the ability to interact with the browser. You need to know a URL in order to fetch it.

However, you mention that part of what you'd like to do is fetch the user that is currently logged in, so perhaps you might be interested in the '.getActiveUser()' method? It might be a potential solution.

HDCerberus
  • 2,113
  • 4
  • 20
  • 36
  • a) Thanks. I'll look into the XML service. I'm not trying to get the Google user – JompaBoy Nov 21 '14 at 14:49
  • ...and b) I'm not trying to get the Google user but the user logged in, in the Episerver. If that keeps bugging me, I'll try getActiveUser() once more. But my conclusion so far is that it only takes the owner of the sheet/script rather than user that is running the script (in another situation though, a form submittning data to a spreadsheet) – JompaBoy Nov 21 '14 at 14:52
  • It varies. If the script is set to "execute as me" (That is, you, the developer), or does not require authorization it won't return anything, otherwise it will return the username of the user running the script. – HDCerberus Nov 21 '14 at 14:54