How can I search for a specific function and then edit it? - google-apps-script

Unless I'm missing something, the App Script Editor lacks the ability to find a specific function within the project.
I'd like to be able to search for a specific function and then edit it.
Alternatively, how can I view a list of functions within my project (and which .gs file each is in)?
To be clear, I have a number of (logically named) .gs script files within my project each with a number of functions within.

This is not yet an available feature for the new Apps Script IDE - however there is already a fearure request for enabling cross-file search on Google's Issue Tracker:
Search function in Apps Script editor should allow searching of all project files, not just the currently open one.
Google prioritises feature requests by popularity, so make sure to give the issue a star on the above page to let them know this is highly requested.
In the mean time, the legacy editor still has cross-file search available, so you can use this to search in all project files at once.

The new Monaco script editor lacks cross-file search, but the legacy script editor has this feature. So a workaround is to click Use legacy editor in the top right-hand corner and do your search there.
Click the star icon ☆ in the top left-hand corner of issue 175233560 to vote for this feature request and get notified of changes in status.

Yes it does seem to lack that ability as far as I can see. I use control f and then just select between the different files. It keeps the search active between files. Making it possible to find strings in other files. I would prefer if it would just tell me where but I haven't identified that ability as yet.

Related

Google apps script cannot get url parameter from page on new Google site

My current site (Golf League) uses several scripts to allow players to schedule whether they are playing, display various results pages etc. It seems as though the New Google Sites implementation does not allow a parameter to be passed in the page url and get picked up by an embedded Google Web App (published from my script)
This link shows an example https://sites.google.com/site/kitchenergaffers/home/general-gaffers-information/publish/directory-of-results?display=directory
There is my webapp (built from a GAS) that does a doGet(e). The "display" parameter tells this script which page to format and display which it gets by extracting the e.queryString. I use a similar approach for players scheduling their absences. Another url parameter identifies the player who may be changing their availability.
It seems as though this ability is not going to be supported in the New Google Sites, so I am looking for an alternative (and free) web building facility where I can launch GAS web apps and access the page url parameters the same (or similar) way. Wordpress, Wix etc may be candidates, but it is difficult to tell from their introductory info whether it can be done. If someone has already found a site facility and methodology I would appreciate the guidance.
Just in case anyone finds this in a search, I have found a workaround.
What I had missed is that a script can be the target of a URL and will execute in a browser on its own. It does not need a "hosting" page. So to achieve what I need to do, instead of sending the link with the Google sites page, I can send a link with the script directly and it will happily execute in its own browser environment. In some cases, I may need to add a bit of text to the html returned by the script to replace that which was on the Sites page
So this link (below) achieves what I needed. Be aware that the links displayed by the script, are currently still to the original sites page.
https://script.google.com/macros/s/AKfycbxichdoGrHbImuudkJbuhhD00GpHvVvc-Ph_BTpSI4863pMevVx/exec?display=directory

Is there a way of seeing the script code for an action I have performed?

I am new to writing scripts in Google Apps. I am trying to script various actions in Google Docs which previously I would have done through the main user interface. Is there a way of "recording" such actions as they are carried out, analogous to recording a Macro in Excel?
For example, I am creating a Form in Google Docs. Using the main interface, I can add an Image item and upload an image from another source (Google Drive, my desktop, etc.), but I can't work out the script code that would perform this same action. Is there any way to output the script that would have carried out the same action that I have just performed?
Many thanks.
Currently, you cannot 'record' a macro.
There is an issue in the Issue tracker (issue 650) where Google have mentioned that it is not feasible at the moment (Jul 2010). You may star the issue to register your interest to the enhancement request.
I think the real issue is that the GApps scripting functions are manipulations of the underlying object model of the document. The UI also manipulates the underlying object model, but no one has yet created the functions to emulate the UI in GApps script form. Recording the actions would then be a separate step and converting the recorded actions into GApps functions would be yet another step.
So you need to be clear: is your goal to be able to record and play back UI actions, or is your goal to be able to upload an image into a GDoc? You asked about recording and that's the answer you got. Maybe if you asked about how to use GApps to add an image to a GDoc, you would get a more useful answer.
My own personal question would be:
I haven't figured out how to use the GApps documentation very
efficiently yet. I do a lot of fruitless hunting. How do I find in the
docs how to add an image to a GDoc?
I hope this helps.

Modifying Google Drive Apps for education platform vs Browser Extension?

I'm working with a few schools to develop a series of interactive textbooks for students. The textbooks need to have randomly generated exercises, for which I've already developed a prototype.
It's also required that the app is managed entirely through Google Drive (eg, I can't use WordPress or even Google Sites), although I can create my own Apps - so long as those can be installed and accessed through Drive.
What I'd like to do is:
Allow authors to create randomly generated worksheets using Google Forms, similar to how they can with my current generator
Allow authors to click on a menu item in Google Docs that embeds a widget/iFrame inside a Doc
Embed JSX Graphs into a Doc
Log students answers into a Spreadsheet
"Pretty-fy" spreadsheet into a nicer display in an instructors page - either in spreadsheet, doc, or custom Google App
Everything must work off of Google Drive
My questions are:
Is this something that can be achieved purely through Google App Scripts?
Would someone viewing the Docs be able to see the embedded widgets without my App Scripts installed (if this is even how it works).
Can I extend Google Apps (when viewed by a visitor) to show a sidebar with ToC
Can cross-document TOC be built, where a TOC is generated from the Headers of all docs in a folder?
Would it be easier to create a Browser Extension that can search for certain strings (or even better, a placeholder image with "please install extension") in the app and replace them with the interactive widgets?
Browser Extension
Aside from extending Google Apps, I could also create a browser extension that students install that does #2...this would be fairly easy. Of course, "Install" is a scary word for parents, so preferably a solution that doesn't require students to install anything.
I guess, really, my direct question is this: Can Google App Scripts alone extend Drive Apps to create interactive textbooks for students and teacher planners.
As commented by Mogsdad, your question is indeed overly broad. But I'll attempt to answer it.
From the list you things you'd like, only point 3 may be problematic. You'd have to test if JSX Graphs works well with Apps Script Html Services. I'm afraid it won't. But you have other Chart solutions on Apps Script.
From your list of questions:
I don't think so, unless you make some compromises on your requirements.
No, only scripts installed on the document/form/spreadsheet itself can embed widgets on it.
Not with Apps Script, to run/interact with scripts the user must be a collaborator, not a visitor (meaning he must have edit rights on the file). Maybe with a browser extension.
Yes. But if there's "too many" files to be processed, you're likely going to hit some Apps Script quotas that will make your life difficult.
I didn't really understood this question. But browser extensions can surely do more than scripts, but they will require installation on each browser for all your users.

How to login to a website, read data?

I would like to write a GoogleApps script that accesses a website, logins using my credentials, makes a selection from a drop down menu and copies the displayed values to paste them on my active spreadsheet.
Is this possible or should I go about it a different way?
Directly, that is not possible. However if the website offers an API or if the website makes use of URL parameters to pass information about what you've selected, it might be possible if the website also uses HTTP authentication.
Absolutely possible. Capture what you need to do for authentication. Repeat it with Google Apps script.
Capture what you need to do with the drop downs. Repeat it with Google Apps script.
Quite generic instructions, but you didn't give any more specificity to your problem. Use something like TamperData addon for Firefox to capture/see what Google Apps Script needs to pass back and forth to the server.

Google Form API?

I would like to (programmatically) convert a text file with questions to a Google form. I want to specify the questions and the questiontypes and their options. Example: the questiontype scale should go from 1 to 7 and should have the label 'not important' for 1 and 'very important' for 7.
I was looking into the Google Spreadsheet API but did not see a solution.
(The Google form API at http://code.lancepollard.com/introducing-the-google-form-api is not an answer to this question)
Google released API for this: https://developers.google.com/apps-script/reference/forms/
This service allows scripts to create, access, and modify Google Forms.
Until Google satisfies this feature request (star the feature on Google's site if you want to vote for it), you could try a non-API approach.
iMacros allows you to record, modify and play back macros that control your web browser. My experiments with Google Drive showed that the basic version (without DirectScreen technology) doesn't record macros properly. I tried it with both the plugin for IE (basic and advanced click mode) and Chrome (the latter has limited iMacro support). FYI, I was able to get iMacros IE plug-in to create questions on mentimeter.com, but the macro recorder gets some input fields wrong (which requires hacking of the macro, double-checking the ATTR= of the TAG commands with the 'Inspect element' feature of Chrome, for example).
Assuming that you can get the TAG commands to produce clicks in the right places in Google Drive, the approach is that you basically write (ideally record) a macro, going through the steps you need to create the form as you would using a browser. Then the macro can be edited (you can use variables in iMacros, get the question/questiontype data from a CSV or user-input dialogs, etc.). Looping in iMacros is crude, however. There's no EOF for a CSV (you basically have to know how many lines are in the file and hard-code the loop in your macro).
There's a way to integrate iMacro calls with VB, etc., but I'm not sure if it's possible with the free versions. There's another angle where you generate code (Javascript) from a macro, and then modify it from there.
Of course, all of these things are more fragile than an API approach long-term. Google could change its presentation layer and it will break your macros.
Seems like Apps Script now has a REST API and SDK's for it. Through Apps Script you can generate Google Forms. This API was really hard to find by trying to google for it and I haven't yet tested it myself, but I am going to build something with it today (hopefully). So far everything looks good.
EDIT: Seems like the REST API I am using works very well for fully automated usage.
In March(2022) google released REST API for google form. API allows basic crud operation & also added support for registering watches on the form to notify whenever either form is updated or a new response is received.
As of now (March 2016), Google Forms APIs allow us to create forms and store them in Google Drive. However, Forms APIs do not allow one programmatically modify the form (such as modify content, add or delete questions, pre-filled data, etc). In other words, the form is static. In order to serve custom, external APIs are needed.