I'm trying to use the PivotCharts library that is recommended in on the apps developer site here: https://developers.google.com/apps-script/notable-script-libraries - but when I try replicating the example code:
function createReport(){
var app = UiApp.createApplication().setWidth(700).setHeight(450).setTitle('My report');
var data = SpreadsheetApp.openById('0AnxR7WfXrj7adFRnVEFTQ2NldGJodUtCZDF2U0hVNUE').getSheets() [0].getDataRange().getValues();
var panel = PivotChartsLib.createColumnChart(data, 3, 4);
app.add(panel);
SpreadsheetApp.getActiveSpreadsheet().show(app);
}
The initial chart loads, but when you try to pivot you get an error "Type Error: can not call method "apply" of undefined"
I've tested on different computers, so I think it is an issue with the library itself. I'm not sure how to access that code though to try and fix it.
I saw same error.
then i copied code from PivotCarts library,
it worked fine.
it seems pivot charts library ui need apply function,
that should be global scope function , but PivotCharts's apply function scope is into PivotCharts object.
Related
I'm trying to teach myself to use Google Apps Script, but somehow every function I try returns this error immediately. And since I'm a huge beginner, I don't know what I'm doing wrong.
Here's a simple example of a code I tried to run:
function myFunction(){
//application
//file
var ad = DocumentApp.getActiveDocument();
var docBody = ad.getBody () ;
var paragraphs = docBody.getParagraphs();
//paragraphs[0]. setText ("MY NEW TEXT"):
//var attr = paragraphs[0].getAttributes() ;
//Logger.log(attr);
paragraphs[0].setAttributes({FONT_SIZE:40});
}
Yet no matter what I'm running really, I get this:
TypeError: Cannot read property 'getBody' of null
myFunction # Code.gs:5
What am I doing wrong?
I have an open Google Doc, I've allowed permissions to run the script project. What else should I try? Thanks.
In order to get getActiveDocument() working you need to use it in a script that is container-bound:
Create a new Google Document
Go to Extensions > Apps Script
Run your function inside of it.
If your script is not container-bound, you need to use the openById(id) or openByUrl(url) methods, in order to retrieve a Document
Adblock software was preventing the running somehow. Disabled it and runs fine now. Disregard!
I want to do some text/paragraphs replacement in Google Docs that are automatically created by an add-on (autoCrat). I tried this successfully on a bound script but now that I want to try it on a standalone script, I get this error:
TypeError: Function getBody not found in the DOCUMENT-NAME object.
I don't understand.
Do I need to call a bound script from the standalone script or something like that?
(I hope not.)
The GAS documentation is not helping at all with this, at least with my understanding of what a standalone script is. Maybe it's a trivial error, but all the examples I found here are for bound scripts, which are not what I'm doing (I've already done a bound script and it's working fine).
This very simple code won't work for a standalone script and I don't understand why :
function Myfunction() {
var file = DriveApp.getFileById('doc-id');
var body = file.getBody();
Logger.log(body);
}
You are getting that error because the class returned by getfilebyID is of type File, not Document.
Try something like this:
let LogFile = DriveApp.getFileById('doc-id');
let LogDoc = DocumentApp.openById(LogFile.getId());
LogDoc.getBody()
I am trying to create an app script for a Google Spreadsheet that I have. I created a script for another sheet a couple of years ago and I can't remember how to to get the component ID.
Here's the code:
var pointsSheet = SpreadsheetApp.openById('1o8_f063j1jYZjFEnI_P7uAztpnEAvQ6mc3Z1_Owa69Y');
function doGet() {
var app = UiApp.createApplication();
app.add(app.loadComponent("Marks")); //IT IS NOT CALLED MARKS!
var panel = app.getElementById("VerticalPanel1");
var text = app.createPasswordTextBox().setName("text");
var handler = app.createServerHandler("getResults").addCallbackElement(text);
panel.add(text);
panel.add(app.createButton("Get Record", handler));
//SpreadsheetApp.getActiveSpreadsheet().show(app);
return app;
}
...
The commented part where it says "IT IS NOT CALLED MARKS" is the part I'm talking about. In my other script this works, but in the new script it doesn't work. How do I find the component name (if that's what it's called)?
You are trying to run a script that uses the GUI Builder, a couple of years ago it was possible but now it is not anymore (since october 2013)! See here.
I saw that because you are using app.loadComponent("Marks"), which was the method to call the Ui components created in the GUI Builder.
The old apps built with it still work but you can't create/modify it.
EDIT following your comment :
You will have to build your UI from scratch using either UiApp - which uses the same elements as the GUI builder and the same syntax - or HTML Service.
The latter is much more powerfull but uses a completely different approach as it uses client JavaScript in combination with server code. Take a look at the docs and tutos and make your choice ;-)
I have a script that is both published and been working for months that has suddenly stopped being able to find click handlers (no change to the code).
IE. I get an error like this:
Error encountered: Script function not found: interfaceClass.myClickHandler
"interfaceClass.myClickHandler" does, in fact, exist and it is registered
var indF = app.createCheckBox("Create individual files")
.setName('create')
.setId('createBox');
var chandler = app.createServerHandler('interfaceClass.myClickHandler');
indF.addClickHandler(chandler);
It also doesn't seem to be anything specific to this handler. ALL click handlers are failing.
Given this was working, I'm almost positive this is a result of Google doing an update that broke our code (which they've done in the past). But I need to know what they changed so I can work around it. Does anyone know?
So apparently what they broke is that app.createServerHandler can no longer find functions defined like so:
var obj = {};
obj.method = function (e){
};
You must now use functions declared the following way:
function method(e){
}
The bigquery functions in our apps script had been working fine all along but 18/06/2013 onwards setProjectId(), setQuery() and other BigQuery functions have stopped working.
On using these functions, the variables remain undefined when they should ideally be populated.
A small sample script which reproduces this issue:
var newJobReference = BigQuery.newJobReference().setProjectId(yourProjectID);
var jobConfig = BigQuery.newJobConfiguration().setQuery(yourJobQueryConfiguration);
Anyone facing the same issue? What might be causing this?
Issue is resolved when I use:
var newJobReference = BigQuery.newJobReference();
newJobReference.setProjectId(yourProjectID);
Instead of:
var newJobReference = BigQuery.newJobReference().setProjectId(yourProjectID);