Forum Discussion
exporting variables to be read in a Google docs spreadsheet
Hi,
I appreciate this was a while ago, but wondered if anyone can help.
I can get the variables to pass to the google spreadsheet, but I too am seeing the pop up error/message from website. Although it does let you close this message and carry on with the course (and the variables go onto the spreadsheet) - I'm struggling to get rid of it.
Can any one help??
Cheers, Laura
PS - Exported as SCORM running in VLE where the users have to use IE 11 (created in SL1)
PPS - should also have said that just using the scripts nicked from these forums without alterations except to add my spreadsheet/form and variable details (thank you!).
SCRIPT used in Google:
function myFunction() {
var SCRIPT_PROP = PropertiesService.getScriptProperties();
function doGet(e){
return handleResponse(e);
}
function doPost(e){
return handleResponse(e);
}
function handleResponse(e) {
var lock = LockService.getPublicLock();
lock.waitLock(30000);
try {
var doc = SpreadsheetApp.openById(SCRIPT_PROP.getProperty("1EMJiuiqZ7R8tX9MbeSrjrKEjgGfhw16LfLAYQ1_bOaY"));
var sheet = doc.getSheetByName(SHEET_NAME);
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 = [];
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]]);
}
}
sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
return ContentService
.createTextOutput(JSON.stringify({"result":"success", "row": nextRow}))
.setMimeType(ContentService.MimeType.JSON);
} catch(e){
return ContentService
.createTextOutput(JSON.stringify({"result":"error", "error": e}))
.setMimeType(ContentService.MimeType.JSON);
} finally {
lock.releaseLock();
}
}
function setup() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
SCRIPT_PROP.setProperty("1EMJiuiqZ7R8tX9MbeSrjrKEjgGfhw16LfLAYQ1_bOaY", doc.getId());
} }
SCRIPT USED IN STORYLINE
var player = GetPlayer();
$.ajax({
url: "https://docs.google.com/forms/d/1SzbvgcnV93aqOfHU4ycIlrJhD2BH4PpanB039l7Wgao/formResponse",
type: "POST",
data: {"entry.174521765" :player.GetVar("name"), "entry.1135805308":player.GetVar("id"), "entry.1806056227" :player.GetVar("colour")},
success: function(data)
{
alert(data);
}
});
return false;
THING ADDED TO STORY.HTML <HEAD>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
It works, the variable data gets filled into the Google sheet, it just brings up the error message attached - the user can close the error message and carry on as normal, it's just not a great user experience.
Thanks in advance!