Triggering site in new tab or window in Google Sheet - javascript

I use autocrat to mail merge legal documents with a database in Google Sheet. Autocrat does instantaneously trigger when a Google Form is submitted, which is great, but I also require the task to perform automatically. Through some searching, I learnt that a modified Google Form link can submit Google Forms with pre=filled answer.
This is where I am stuck.
I have set up (or I think I have) the script in Google Sheet to onChange (Insert_row, edit). I'd like that to trigger a new window or tab to open, going to the modified Google Form link, thereby triggering the form, which then triggers autocrat, then I can have my documents mail merged automatically.
This is the code I am using, which isn't working.
function openWindow(url) {
window.open('url', '_blank');
window.focus();
}
Is this a coding error, or is this a limitation within Google Script? Most of the codes I found involves using a button and then clicking it, I also read that there are browser limitations for auto pop-ups.

Short answer
While Google Sheets and Google Forms use HTML, JavaScript and related things to work, there are some restrictions. See the guides to learn about what could be done.
Explanation
JavaScript window object doesn't work on your script because the code on .gs files runs on Google servers (server-side) not on the user browser (client-side).
See Dialogs and Sidebars on Google Apps Script to learn the basics about how to show a dialog.

Related

How to use Google Apps Script as a submission form

I'm relatively new to Google Apps Script. I'm trying to build a script, as well as Html, to create a site where I have people submit their names, age and so on (basic info for a test site). After they do so I want it the information to be automatically recorded into a google sheets file. Issue I'm having is that I don't know how to record the submissions using Google Apps Script to the google sheets file. I also want an email sent to me automatically after someone submits something. I tried looked at the API Ref but don't really have a solid starting point. I'm learning Javascript now but would like an idea of how Google Apps Script would work if I tried making a program like this. Thank you
Google Forms (https://www.google.com/forms/about/) will do most of this for you without any code. Once you have a basic form working, you can enhance that form with Google Apps Script if needed.

Popup notification in gmail?

What is this popup notification in gmail, and how can I replicate it? I assume it is javascript. I'd like to use it in an outside google web project but I don't see anything in the API about what it is called.
That pop-up message that you see is not produced by the Gmail, it's already in your Spreadsheet when updating Custom Menus.
If you want something like that, then you can use Dialogs in Spreadsheet using the Google Apps Script.
You can either use Alert dialogs, Prompt dialogs or Customs dialogs that you want for your Docs or Spreadsheet.
Just visit the link of different dialogs, it will give you a sample code on how to do it :)
You'll need to use a browser extension.
Try out https://www.inboxsdk.com

how to check google analytics code fired through python

I have a website on which Google Analytics code fires (through Google Tag Manager). The site has a lot of pages and I want to check if Google Analytics code fires on all pages. One way would be to open the URL, open GA debugger and check the pageview firing in the console.
Since there are a lot of URLs which need to be checked, is there a way to automate this process (preferably by Python)
Edit:
What I've tried so far:
I've managed to get the fetch the source code of the pages and then regexing my way to find specific code snippets (of GA and GTM) You can find the code here. But the problem is this will fetch just the static code. Any pixels/codes firing after the page actually loads will not be captured.
The issue with using Selenium is that I will be performing this test for possibly thousands of URLs. Selenium will slow the process down considerably.

Getting the javascript "document HTML DOM" info within Google Apps Script

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?
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.

Auto form filling using java script

My requirement is to write one script when I run the script it opens the page and fill the fields and automatically take me to next page.
For e.g. Script for www.irctc.co.in. When we login to irctc it ask the user name and password and when click on submit it redirect to next page.
I want to write a script in such a way that I just click on the script it internally does all these things and I could see the next page.
I am unable form where I should start.
I think you are looking for something like Greasemonkey: https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
Greasemonkey is a Mozilla Firefox extension that allows users to install scripts that make on-the-fly changes to web page content after or before the page is loaded in the browser.
If you use a different browser, then you can refer to: http://en.wikipedia.org/wiki/Greasemonkey#Equivalents_for_other_browsers
Check Watir - Web Application Testing in Ruby. Although it is used for automation, it might solve the purpose here. With Watir, you write scripts in ruby and execute it and then see the magic. More information can be found here

Categories