Forum Discussion
Exporting Variables into a Google Spreadsheet
Hello Kate,
I am trying to get the record of the learner's record exported from the storyline 360 courses to google sheet for backend record tracking. I have created the demo version, where I have created a few slides, the first slide to collect the student's record using 'text entry.' On the second slide, I have made a demo quiz question, the third slide is the result slide, and on the last slide, I have used the variables to get the student's record on the slide and set up the javascript to export the data using the option "When the timeline starts on this slide."
I have set up the google sheet as per the instruction on this article and set up the javascript variables on my Storyline 360 course. But somehow, the data is not pushed from the storyline to the google sheet. Also, I want to capture "Results2.ScorePercent" on the google sheet to check the score of the students.
Here is my google sheet script code as per this article:
// 1. Enter sheet name where data is to be written below
var SHEET_NAME = "DATA";
// 2. Run > setup
//
// 3. Publish > Deploy as web app
// - enter Project Version name and click 'Save New Version'
// - set security level and enable service (most likely execute as 'me' and access 'anyone, even anonymously)
//
// 4. Copy the 'Current web app URL' and post this in your form/script action
//
// 5. Insert column names on your destination sheet matching the parameter names of the data you are passing in (exactly matching case)
var SCRIPT_PROP = PropertiesService.getScriptProperties(); // new property service
// If you don't want to expose either GET or POST methods you can comment out the appropriate function
function doGet(e){
return handleResponse(e);
}
function doPost(e){
return handleResponse(e);
}
function handleResponse(e) {
// shortly after my original solution Google announced the LockService[1]
// this prevents concurrent access overwritting data
// [1] http://googleappsdeveloper.blogspot.co.uk/2011/10/concurrency-and-google-apps-script.html
// we want a public lock, one that locks for all invocations
var lock = LockService.getPublicLock();
lock.waitLock(30000); // wait 30 seconds before conceding defeat.
try {
// next set where we write the data - you could write to multiple/alternate destinations
var doc = SpreadsheetApp.openById(SCRIPT_PROP.getProperty("12msX31fJ5bqw2ajJk4oJxPjFkSs5x-Rbot2PspwuTEs"));
var sheet = doc.getSheetByName(SHEET_NAME);
// we'll assume header is in row 1 but you can override with header_row in GET/POST data
var headRow = e.parameter.header_row || 1;
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
var nextRow = sheet.getLastRow()+1; // get next row
var row = [];
// loop through the header columns
for (i in headers){
if (headers[i] == "Timestamp"){ // special case if you include a 'Timestamp' column
row.push(new Date());
} else { // else use header name to get data
row.push(e.parameter[headers[i]]);
}
}
// more efficient to set values as [][] array than individually
sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
// return json success results
return ContentService
.createTextOutput(JSON.stringify({"result":"success", "row": nextRow}))
.setMimeType(ContentService.MimeType.JSON);
} catch(e){
// if error return this
return ContentService
.createTextOutput(JSON.stringify({"result":"error", "error": e}))
.setMimeType(ContentService.MimeType.JSON);
} finally { //release lock
lock.releaseLock();
}
}
function setup() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
SCRIPT_PROP.setProperty("12msX31fJ5bqw2ajJk4oJxPjFkSs5x-Rbot2PspwuTEs", doc.getId());
}
Here are the variables I have used to collect the data:
Name
LastName
SBUID
Here is the javascript-based on this article:
var player = GetPlayer();
$.ajax({
url:
"https://script.google.com/macros/s/AKfycby-NIv6hl6a71GnO8jF9wC-Ac5jq0os3y1PjD0rWzzNjHY1NgQ/exec",
type: "POST",
data: {"Name": player.GetVar("Name")
, "LastName": player.GetVar("LastName")
, "SBUID": player.GetVar("SBUID")},
success: function(data)
{
console.log(data);
},
error: function(err) {
console.log('Error:', err);
}
});
return false;
Can someone help me to find the problem of why this thing is not working? I also want to populate the student's percentage/score received in the quiz using the inbuilt variable. Is there any changes/update has been done on google's side or Articulate side, and that is why codes are not responding?
Thank you,
Pratik Parekh