Forum Discussion
Articulate Storyline: Export to Google Drive
Hello,
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 two slides, the first slide to collect the student's record using 'text entry'. On the second 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 as well. But somehow the data is not pushed from the storyline to the google sheet.
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. Enter the KEY of your form
var KEY = "1I-2bT8Nh5rwUCtDF3bnsUic_usfNcepsJ_bKc1GBq18";
// 3. Run > setup
// 4. 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)
// 5. Copy the 'Current web app URL' and post this in your form/script action
// 6. 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(KEY));
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] == "SystemDate"){ // 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(KEY, doc.getId());
}
Here are the variables I have used to collect the data:
StudentFirstName
StudentLastName
StudentID
BuildingRoomNumber
StudentEmailID
Here is the javascript-based on this article:
Javascript 1:
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = '//code.jquery.com/jquery-1.11.0.min.js';
script.type = 'text/javascript';
head.appendChild(script)
Javascript 2:
var player = GetPlayer();
//PLACE YOUR WEB APP URL
WEB_APP_URL: "https://script.google.com/macros/s/AKfycbzZtaVUYgduE6riPnPUSsajbQYdnJ2y16-GoH4egGSXpyB0Ruw/exec";
// STORE ARTICULATE STORYLINE VARIABLES
// "Columnname_Google_Spreadsheet" : player.GetVar("Name_Storyline_Variable")
// ATTENTION: Use a comma if you use multiple Storyline variables
storyline =
{
"date" : new Date().toJSON().slice(0,10), //STORE DATE
"StudentFirstName" : player.GetVar("StudentFirstName"),
"StudentLastName" : player.GetVar("StudentLastName"),
"StudentID" : player.GetVar("StudentID"),
"BuildingRoomNumber" : player.GetVar("BuildingRoomNumber"),
"StudentSbuEmailID" : player.GetVar("StudentSbuEmailID")
}
Javascript 3:
//DELAY SO JQUERY LIBRARY IS LOADED
setTimeout(function (){
//Export to Google
$.ajax({
url: WEB_APP_URL,
type: "POST",
data : storyline,
success: function(data)
{
console.log(data);
},
error: function(err) {
console.log('Error:', err);
}
});
return false;
}, 1000);
Can someone help me to find the problem of why this thing is not working? I also want to populate the student's the percentage/score received in quiz using the inbuilt variable. Is there any changes/updated has been done on the google's side or Articulate side, so the codes are not responding?
Thank you,
Pratik Parekh