Sending Data to Google Sheet

lewws shared this question 3 years ago
Answered

Hi

I came across this.

https://www.geogebra.org/m/fkSaFhqF

but after following instructions, unable to achieve the goal.

Anyone can help?

Comments (18)

photo
1

Looks like you need to replace this with a non-jQuery version


jQuery.ajax({url:scriptURL, data: { "id":app_name, "Class":class0, "Class Number":num, "x-coord":x, "y-coord":y },

https://stackoverflow.com/q...

photo
1

Thanks Michael.

The concepts in the links a little beyond me for now.

Was hoping to just use some templates to connect just the variables and record to Google spreadsheet.

photo
1

Here's an updated, working version:https://www.geogebra.org/m/uhsmpcpe

photo
1

Mighty grateful ! Michael..This could be a breakthrough for some of my colleagues wishes as they begin to see how useful Geogebra can be with integration using Javascript!

photo
1

My copy is working well.

For those going to use this, do note that besides publishing the script to make it a web app enabled Google Sheet and getting a url to point to (Step 2 (h) , it is important to Run the function called setup (Step 2 (d))

At first I missed this and Run some other function in the list. The Geogebra data got lost in space!

Very glad to be able to have the template to link Google sheet with students' responses on Geogebra activities from now on!

photo
1

Love this Michael!

I'm wondering if it might be possible through the Geogeba Javascript API to be able to get the username of the person logged in to Geogebra. I'm thinking that if I use this in my classes, I want to be able to automatically record the username rather than need to add a field to the applet that asks for the username. Please let me know if this might be possible.

Thanks!

Jason

photo
1

Sorry, we won't be adding that

photo
1

Dear Michael,

I have rigorously followed the steps in https://www.geogebra.org/m/uhsmpcpe and it works for me.


With confidence, I created a new Google sheet with different headers and tinkered with the codes, hoping it would work.

I have various errors which ranges from sendData is not defined to data not appearing in the Google sheet?

Could you please help me out?

Attaching my files.

https://docs.google.com/spreadsheets/d/13xhKtdWVliGgSo40PiQgnzWiYH925sZmfhSb_EQ3OIE/edit#gid=0

https://www.geogebra.org/cl...

photo
1

1) close properties view otherwise buttons don't work

2) num isn't defined in global JavaScript

 if (num !== "") {

photo
1

Dear Michael, Thank you for your prompt reply.

1) I was testing and saving at the moment. I guess that is why you see the properties view being opened up.

2) if (num !== "") { That is from the original script. I guess it meant if the fields are empty, send an alert? (alert("Please input the class and class number");??

Do guide me along.

photo
1

Hi Shixiong,

You can do your variables in Geogebra script (essentially the Geogebra commands) but to extract the values and pass it to Google Sheets you need to use Javascript. See the link below.

https://wiki.geogebra.org/e....

You can use the command buttons but you will have to switch to Javascript option to extract values from the Geogebra objects.

And you connect to the variables in the global javascript environment, the scripts which Michael provided.

photo
1

Hi Michael,

Need some help with the data transfer.

text variable is texttest1 = (x+4)^2 + 3

Apparently (x+4)^2 + 3 is transferred as (x 4)^2 3 with the "+" missing.


Javascript code snippets relevant to above in button3

var testtxt1 = ggbApplet.getValueString("texttest1");

if (confirm("Confirm to submit?\nClass: " + class0 + ", class num: " + classNum + ")")) {

sendData(class0, classNum, qnum, feedback1, feedback2, feedback3, feedback4, feedback5, testtxt1);

}


Under Global Javascript :


url += "&Test%20Function=" + tt1;


The google spreadsheet is at

https://docs.google.com/spr...


Is there some Javascript command for handling the character "+" within a string?


Regards,

lewws

photo
1

Yes:

encodeURIComponent()
eg https://murkle.github.io/ut...

photo
1

Hi Michael,

Many thanks, that was fast!

Trying to rectify now.

photo
1

Works like magic.

I thought I needed to use decodeURIComponent() as well, but apparently it was not necessary.

Thanks again.

photo
1

Completed testing, all ok . Sharing and also keeping this for future reference

https://www.geogebra.org/m/yeadyc5k

photo
1

Hi, I've seen some of you have successfully replicated the method described in https://www.geogebra.org/m/uhsmpcpe


I've been trying to make it work but I'm stuck somewhat in the beginning. After I create the Google Apps Script, and I try to test the script (step 2-i), I get an error from google:


TypeError: Cannot read property 'callback' of undefined (line 69, file "code")



The line mentioned in the error is in this section:

52    // more efficient to set values as [][] array than individually
53    sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
54    output = JSON.stringify({"result":"success", "row": nextRow});
55    if (e && e.parameter && e.parameter.callback){
56      // return jsonp success results
57      return ContentService
58          .createTextOutput(e.parameter.callback+"("+ output + ");")
59          .setMimeType(ContentService.MimeType.JAVASCRIPT);
60    }
61    else{
62      // return jsonp success results
63      return ContentService
64          .createTextOutput(output)
65          .setMimeType(ContentService.MimeType.JSON);
66    }
67  } catch(e){
68    output = JSON.stringify({"result":"error", "error": e});
69    if (e.parameter.callback){

I don't have enough programming experience to debug this, and searching and google didn't get me far, something is undefined and that's all I got.


Can someone point me in the right direction?

My copy of the spreadsheet is:

https://docs.google.com/spr...


And the script is in https://script.google.com/m...


Thanks

Comments have been locked on this page!

© 2023 International GeoGebra Institute