server handlers in Google app script sheets not working - google-app-engine

I get this error when trying to execute this code from the script manager menu.
Error encountered: Script function not found: function click(e) {
var app = UiApp.getActiveApplication();
app.getElementById('label').setVisible(false);
SpreadsheetApp.getActiveSpreadsheet().show(ui);
return app;
}
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
Logger.log(row);
}
};
function onOpen() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "ShowUi",
functionName : "showSidebar"
}];
spreadsheet.addMenu("Script Center Menu", entries);
};
function click(e) {
var app = UiApp.getActiveApplication();
app.getElementById('label').setVisible(false);
SpreadsheetApp.getActiveSpreadsheet().show(ui);
return app;
}
function showSidebar(e){
var ui= UiApp.createApplication()
.setTitle('My UiApp Application')
.setWidth(250)
.setHeight(300);
var button = ui.createButton("I am a button!");
var handler = ui.createServerHandler(click);
button.addClickHandler(handler);
var label =ui.createLabel('The photograph on the dashboard taken years ago...').setId('label').setVisible(false);
handler.addCallbackElement(label).addCallbackElement(button);
ui.add(label);
ui.add(button);
SpreadsheetApp.getActiveSpreadsheet().show(ui);
return ui;
};
I'm sorry that I had to post here for probably obvious but I could not find the answer anywhere else on the internet. Any solution or alternate way i could do the same thing would be greatly appreciated. thanks!

Try something like this:
function showSidebar(e){
var ui= UiApp.createApplication()
.setTitle('My UiApp Application')
.setWidth(250)
.setHeight(300);
var label = ui.createLabel('The photograph on the dashboard taken years ago...').setId('label').setVisible(false);
ui.add(label);
ui.add(ui.createButton('I am a button!', ui.createServerHandler('onClick')).setId('button'));
SpreadsheetApp.getActiveSpreadsheet().show(ui);
return ui;
};
function onClick(e) {
var app = UiApp.getActiveApplication();
app.getElementById('label').setVisible(false);
//SpreadsheetApp.getActiveSpreadsheet().show(ui);
app.close();
return app;
};

Related

I am getting an error running this code loading data from excel sheet into google firebase using google cloud service account both of same mail

function getFirestore() {
var email="busdata-account#export-815a4.iam.gserviceaccount.com";
var key = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDIBWAXxbEGco/p\nr6sEuBWiHJTayXcxD5bQjJNeMCHFnf3DlYxS9HPw3TG/vJBqwIMWKgd9waO9l4M1\nz3+P7obaOJ9OuwV30ZXrzE2F3+i8rnF009HxFGYIpHl3m6QffJ2nLnadfSik7HSv\nhDXHhQodgLkGidLXjLhPwb1hI7Cq96HFPPYqTu1oZqDgl9KMwyI+YgYIhoM+j4uo\n8nYkPErA2Q4hc3cI78Yl1mxAB5Ew1hnN8sPv3jtiXSm1irWI1MkITYcBteT9jRVm\ngR2Bvwu59XCqiX7jJ3fB41DpJcZq9oX6GpWfh846gKio0jaTGcjQx3SmlVUCEkgn\nIv/RKvy7AgMBAAECggEAYaqiQ6lPqa7Jz5jrwDektI4RLw2dihKrGPTzRlPpQaXG\nEbjVlnHvpOZU0uMff0i2GV33X3PsYHh5ZI6Hon+dUDPCsf5HCr0HX+ZX2i09Ztgk\n5R9CzV0g/0pUV09joc5G6qmY2IiTDoi45zT+z4gKKuK+Nc+ZaI+5NZSLxMFZE/lN\n2c6ANbDXA5aezAzit38LcAZ0QLp4VsOY4Hlh+JYjVrZNAbtllRYkuK7fq7bus+fs\nBbqWvKgqjChLwVu8efuUiOvN/kjV84TqRov9Kg7b+7ozl3HSYOfw6NTE9M/aZ54l\naav+YAnoBSWmgG2NuhOmzs2yFf1VctEmRxquKMZ1hQKBgQD0gCETgMxocFGedk1P\nxzL+0plIfnav9GK2n96Pi0rpnyId7xpDdVlfBnkwplgPHDELRIpdbPyjz4408Jn4\ndoV2jSsUKR4ziDxRos2MKFDqA7MJwLYgNa/1hqfpF8bbYR5g7vpPZyT3/gWC/Dni\nndUMIMq+ikxgv70RGXVSh21cLQKBgQDRbbKODtT03CIofDioLyCWsM/aoyvwvEQP\nBaCx7CkkpVXeuosHua9jUekfsSsbWwTGnuP9o5DDgpwkQVzNXIxZXm6rCVZP9PqC\n/mgKDRNAtfU5g07WWpoAbFiJ7b1nJQ40H+sifx5kucDz8DewMAZJdiwKHZ4a9RG9\nRfdEAYyFhwKBgDXGUIAHne2CdpERl+Np/m9JRmlJVzVP3L4p3ztW+Xz0gP5wbihU\nEPnzZIgsrcV0/9xokL4HkHE+3xoJqPOarbPrTIQ8nuXamtmhou+mllVBxwjoF6Zx\n6Gdp3FhJ4HSzoYjURr1cBCd++Rtb+ic7a3YlaDIMHMxSn3S5UrJ6ErVpAoGBALiN\n2/C1/1J8fxmARolnZmeFDtZUPs+ZiLxYMEE6pRMnJCHv777yEi4LK84C2cL0laPW\nt4F314WDHsgQVZCfgwrqXcoZo1c4wl4XhWV+Gj5HWv/AyAO7ucSvteJugB9aF0c1\n7Ybr0MPgsboGMXzxBUlNewe7C+4jkuthscHbP5MXAoGAUL6S6UEXvl1I1a3xbvHo\nv5wv+5fiP4ODq2XgNs6z4gFfTUrjb3CryHqg4I1OYPmq2d8UZ5mDkXPoSXmuz6Wr\nm57NW3d5Oio17vk2IXrzIFZ1MKEm8qu2aLzBCOEeY/fge6Lkyx0Z6ALpwbjPakZD\nrZLeFrU13pKQHKmLQknnoqk=\n-----END PRIVATE KEY-----\n";
var projectId = "export-815a4";;
return FirestoreApp.getFirestore(email,key,projectId);
}
function myFunction() {
const firestore=getFirestore();
var ss = SpreadSheetApp.getActiveSpreadsheet();
var sheetname = "busData";
var sheet = ss.getSheetByName(sheetname);
var lastRow = sheet.getLastRow();
var lastCol = sheet.getLastColumn();
var dataSR = 5;
var sheetRange = sheet.getRange(2,1,lastRow-dataSR+1,lastCol);
var sheetData = sheetRange.getValues();
var sourceLen = sheetData.length;
for(var i=0;i<sourceLen;i++){
if(sheetData[i][1] != ' '){
var data = {};
var sheetData = sheetRange[i][0];
data.place =sheetData[i][1];
data.busId= sheetData[i][2];
data.timeValue = sheetData[i][3];
data.hour = sheetData[i][4];
data.minute = sheetData[i][5];
data.slot = sheetData[i][6];
Logger.log(data);
firestore.createDocument("busData",data);
}
}
}
//enter image description here
//here is my excel sheet link: i am trying to load into firebase its giving an error //of semi-colomn but every semi-column is in its place . ac any one help.
//here is my excel sheet link:[text]//(https://docs.google.com/spreadsheets/d/1zVaLfQ1YC-aKJwzDAHmIBlzc2YfU4GpDnubBnNhOcRc/edit?usp=sharing)
Can anyone help me? I am doing this watching a Youtube video and I am a beginner.

Issue with Google Apps Script code copy-paste from Gsheet file

I've created a code to copy-paste the values from the most recent uploaded Gsheet file to another. The code is supposed to copy-paste only values that fulfil a cell condition.
The problem is, this code takes to long to run and doesn't finish to copy all values before having a run-time error.
The file has about 300.000 cells and the final amounts to be pasted on the 2nd file have about 90.000 cells.
Does anyone have a recommendation on how to proceed?
Thank you so much for your kind support.
function Master_Run_DB() {
Copy_EUDB();
}
function Copy_EUDB() {
var myLink = extractLink_EUDB();
sendData_EUDB(myLink);
}
function extractLink_EUDB() {
var newData = new Date().toLocaleString();
var drive = DriveApp.getFolderById("link to file");
var file = drive.getFilesByType(MimeType.GOOGLE_SHEETS);
var link = file.next().getUrl();
var ss = SpreadsheetApp.getActiveSpreadsheet();
return link
}
function sendData_EUDB(link) {
var mainSS = SpreadsheetApp.openById("link to file");
var lastRow = mainSS.getSheetByName("Database").getLastRow();
mainSS.getSheetByName("Database").getRange("A2" + ":R" + lastRow).clearContent();
var baseSS = SpreadsheetApp.openByUrl(link);
Logger.log(SpreadsheetApp.getActiveSpreadsheet().getUrl());
var lRow = baseSS.getSheetByName("Sheet1").getLastRow();
for (var i = 2; i <= lRow; i++) {
var cell = baseSS.getRange("G" + i);
var val = cell.getValue();
if (val == "EU") {
var sourceData = baseSS.getSheetByName("Sheet1").getRange("A" + i + ":R" + i).getValues();
var to = mainSS.getSheetByName("Database").getRange("A" + i + ":R" + i).setValues(sourceData);
}
}
};
Hello again,
Now that the new code is working, I was trying to add an IF AND clause to the copy-paste. The objective would be to copy only values that fulfil the following condition:
Column 7 = "EU"
Column 11 <> "CCCC"
But I'm getting a Syntax Error. Any advice?
Thank you in advance for your kind support
function Master_Run_EU() {
var drive = DriveApp.getFolderById("link to file");
var file = drive.getFilesByType(MimeType.GOOGLE_SHEETS);
var link = file.next().getUrl();
var ss = SpreadsheetApp.openById("link to file");
const sh=ss.getSheetByName('Database');
sh.getRange(2,1,sh.getLastRow(),22).clearContent();
var dbss = SpreadsheetApp.openByUrl(link);
const dbsh=dbss.getSheetByName('Sheet1');
var oA=[];
var vs=dbsh.getRange(2,1,dbsh.getLastRow()-1,22).getValues();
vs.forEach(function(r,i){
if(r[7]=="EU" && r[11]<>"CCCC") {
oA.push(r);
}
});
sh.getRange(2,1,oA.length,oA[0].length).setValues(oA);
}
Try this:
function Master_Run_DB() {
var drive = DriveApp.getFolderById("1ViOyzIkGOI6G6SMrtmPv4vjL-2-2duHC");
var file = drive.getFilesByType(MimeType.GOOGLE_SHEETS);
var link = file.next().getUrl();
var ss = SpreadsheetApp.openById("13CchyoqiWyvGTnYuG5TWA4cggBS-FsoDkW8XGesDkiY");
const sh=ss.getSheetByName('Database');
sh.getRange(2,1,sh.getLastRow(),18).clearContent();
var dbss = SpreadsheetApp.openByUrl(link);
const dbsh=dbss.getSheetByName('Sheet1');
var vs=dbsh.getRange(2,1,dbsh.getLastRow()-1,18).getValues();
vs.forEach(function(r,i){
if(r[6]=="EU") {
sh.getRange(i+2,1,1,18).setValues([r]);
}
});
}
It would be faster to do it this way:
function Master_Run_DB() {
var drive = DriveApp.getFolderById("1ViOyzIkGOI6G6SMrtmPv4vjL-2-2duHC");
var file = drive.getFilesByType(MimeType.GOOGLE_SHEETS);
var link = file.next().getUrl();
var ss = SpreadsheetApp.openById("13CchyoqiWyvGTnYuG5TWA4cggBS-FsoDkW8XGesDkiY");
const sh=ss.getSheetByName('Database');
sh.getRange(2,1,sh.getLastRow(),18).clearContent();
var dbss = SpreadsheetApp.openByUrl(link);
const dbsh=dbss.getSheetByName('Sheet1');
var oA=[];
var vs=dbsh.getRange(2,1,dbsh.getLastRow()-1,18).getValues();
vs.forEach(function(r,i){
if(r[6]=="EU") {
oA.push(r);
}
});
sh.getRange(2,1,oA.length,oA[0].length).setValues(oA);
}

Issues with AnyGantt

Im using AnyGantt, but Im having problems setting it up correctly.
Here is the full code:
var endpoint = '/api/chart/data/'
var label = []
var start = []
var end = []
var werk = []
$.ajax({
method: 'GET',
url: endpoint,
success: function(data){
labels = data.label
start = data.start
end = data.end
uplant = data.werk
var obj = {}
var finalArray = []
for (var i = 1; i <= start.length; i++) {
var first = { id: i, name: uplant[i] }
obj = { ...obj, ...first }
var periods = { id: labels[i], start: start[i - 1], end: end[i - 1] }
if (obj.periods) {
obj.periods.push(periods)
} else {
obj.periods = [periods]
}
finalArray.push(obj)
}
anychart.onDocumentReady(function () {
var data = finalArray;
var treeData = anychart.data.tree(data, "asTable");
chart = anychart.ganttResource();
chart.data(treeData);
chart.getTimeline().scale().minimum("2018-01-01");
chart.getTimeline().scale().maximum("2020-01-01");
var dataGrid = chart.dataGrid();
dataGrid.column(0)
.title('#')
.width(30)
.cellTextSettings({hAlign: 'center'});
dataGrid.column(1)
.title('Werk')
.width(60)
.cellTextSettings({hAlign: 'left'})
.format(function () {
return this.name;
});
chart.getTimeline().horizontalScrollBar().enabled(true);
/* chart.getTimeline().periods().edit(true); */
chart.getTimeline().edit(true);
chart.getTimeline().tooltip(false);
chart.getTimeline().elements().labels(false);
chart.container("containerx");
chart.draw();
chart.fitAll();
});
},
error:function(error_data){
console.log("error")
console.log(error_data)
}});
I can't click and move the periods (tasks) and I cant scroll.
Thank you very much for any suggestions
Please find below a screenshot of the chart:
Please find below a screenshot of the chart:
Scale range
You are applying the scale min/max correctly:
chart.getTimeline().scale().minimum("2018-01-01");
chart.getTimeline().scale().maximum("2020-01-01");
But then you override the default scale and it drops the min/max settings:
var dateTimeScale = anychart.scales.dateTime();
var dateTimeTicks = dateTimeScale.ticks();
chart.xScale(dateTimeScale);
There's no need to do this! The default Gantt Chart is already a dateTime type. Solution - simply remove those three lines above from your code.
LiveEdit
Your line chart.getTimeline().periods().edit(true); is correct, but due to a little bug in the current version 8.7.0 (Aug 2019) this setter doesn't work for types of elements. To avoid it replace this line with the following line chart.getTimeline().edit(true);.
Scrollers
The Gantt chart doesn't support x/yScrollers, only simple scroll bars.
The following methods the Gantt chart doesn't support:
chart.xScroller(true);
chart.yScroller(true);
For zooming, you can use one of the API functions. This subject is described in detail in the Gantt zooming article.

Why this component doesnt work if I use: polymer init app-drawer-template

Hi Im just a rookie with polymer, I hope this question doesnt sound stupid for you :(
I am triying to make a image gallery and I am using this idea: From this page
<dom-module id="simple-gallery" >
<script>
HTMLImports.whenReady(function () {
(function() {
var current_index = 0;
var image_length = 0;
Polymer({
is: "simple-gallery",
ready: function() {
var images = Polymer.dom(this).querySelectorAll('img');
var container = this.$.links;
for (var img in images) {
images[img].addEventListener('click',this.load_popup);
container.appendChild(images[img]);
}
},
load_popup: function(e, detail, sender) {
e.preventDefault();
var links = document.getElementById('links');
image_length = links.getElementsByTagName('img').length;
var image_url = e.target.getAttribute('data-original');
var modalbody = document.getElementsByClassName("modal-body")[0];
var modal_img = modalbody.getElementsByTagName('img')[0];
modal_img.setAttribute("src",image_url);
var modal = document.getElementsByClassName("modal")[0];
modal.style.display = 'block';
current_index = parseInt(e.target.getAttribute('data-index').replace("s",""));
return false;
},
next: function () {
current_index = current_index + 1;
if(current_index == (image_length + 1) ){
current_index = 1;
}
var current_image = document.querySelectorAll("[data-index='s"+current_index+"']");
image_url = current_image[0].getAttribute('data-original');
var modalbody = document.getElementsByClassName("modal-body")[0];
var modal_img = modalbody.getElementsByTagName('img')[0];
modal_img.setAttribute("src",image_url);
},
prev: function () {
current_index = current_index - 1;
if(current_index == 0 ){
current_index = image_length;
}
var current_image = document.querySelectorAll("[data-index='s"+current_index+"']");
image_url = current_image[0].getAttribute('data-original');
var modalbody = document.getElementsByClassName("modal-body")[0];
var modal_img = modalbody.getElementsByTagName('img')[0];
modal_img.setAttribute("src",image_url);
},
close: function () {
var modal = document.getElementsByClassName("modal")[0];
modal.style.display = "none";
},
});
})();
});
</script>
<template>
I realy dont understand why this code works fine if I use it as in the example, but if I create a proyect with: polymer init app-drawer-template and I use this as an element wich is called from one of the views I have an error :(
Uncaught ReferenceError: HTMLImports is not defined(anonymous function) # simple-gallery.html:91
Surely I am not understanding well something but I dont know why, hope somebody has the time to give me a brief explanation :(
thanks a lot for your time.
I had the same issue so I have added following include in my main html:
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
Which worked for me.

Angular JS range input issue

when the all corners range input is moved, the rest of the inputs work fine but when another corner range is moved the all corners move 1~3 pixels, what could be the issue here?
Demo here:
http://jsfiddle.net/g10fsxym/
code:
var myApp = angular.module('myApp', []);
myApp.controller('myAppCtrlr', function($scope) {
var allcorners = new Quantity(5);
var topLeft = new Quantity(5);
var topRight = new Quantity(5);
var bottomLeft = new Quantity(5);
var bottomRight = new Quantity(5);
$scope.brCorners = allcorners;
$scope.brTopLeft = topLeft;
$scope.brBottomLeft = bottomLeft;
$scope.brTopRight = topRight;
$scope.brBottomRight = bottomRight;
$scope.brTopLeftCorner = function() {
$scope.brTopLeft = topLeft;
}
$scope.brBottomLeftCorner = function() {
$scope.brBottomLeft = bottomLeft;
}
$scope.brTopRightCorner = function() {
$scope.brTopRight = topRight;
}
$scope.brBottomRightCorner = function() {
$scope.brBottomRight = bottomRight;
}
$scope.brAllCorners = function() {
$scope.brTopLeft = $scope.brCorners;
$scope.brTopRight = $scope.brCorners;
$scope.brBottomLeft = $scope.brCorners;
$scope.brBottomRight = $scope.brCorners;
}});
function Quantity(value) {
var qty = value;
this.__defineGetter__("qty", function() {
return qty;
});
this.__defineSetter__("qty", function(val) {
val = parseInt(val);
qty = val;
});}`
Just make a copy of $scope.brCorners (otherwise you are working with references, so when you change one variable the another is also changed).
Demo
$scope.brAllCorners = function() {
$scope.brTopLeft = angular.copy($scope.brCorners);
$scope.brTopRight = angular.copy($scope.brCorners);
$scope.brBottomLeft = angular.copy($scope.brCorners);
$scope.brBottomRight = angular.copy($scope.brCorners);
}

Resources