Announcement

Collapse
No announcement yet.

Sending Data from AMS to GoogleSheet

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sending Data from AMS to GoogleSheet

    Is there other way to translate the Javascript into LUA?

    PHP Code:
    //PLACE YOUR WEB APP URL
    WEB_APP_URL player.GetVar("WEB_APP_URL");

    storyline =
    {
    "Name" player.GetVar("SetStudentID"),
    "Course, Yr. & Sec." player.GetVar("Course"),
    "Time Started" TimeStarted,
    "IP Address" player.GetVar("IPAddress"),
    "Activities" player.GetVar("Activities"),
    "Login" TimeStarted,
    "Logout" player.GetVar("TimeLogout"),
    "Score" player.GetVar("RealScore"),
    "Essay Answer 1" player.GetVar(""),
    "Essay Answer 2" player.GetVar(""),
    }

    //DELAY SO JQUERY LIBRARY IS LOADED
    setTimeout(function (){

    //Export to Google
    $.ajax({
    urlWEB_APP_URL,
    type"POST",
    data storyline,
    success: function(data)
    {
    console.log(data);
    },
    error: function(err) {
    console.log('Error:'err);
    }
    });
    return 
    false;
    }, 
    1000); 

    APPS SCRIPT
    PHP Code:
    //Copy and paste this entire file into your Google Sheets Script Editor (In the spreadsheet, select Tools > Script Editor)

    var SHEET_NAME "Data";

    /* Directions:
    1. Run > setup

    2. Publish > Deploy as web app
    - enter Project Version name and click 'Save New Version'
    - Use the settings: Execute app as Me; Anyone has access, even anonymous

    3. Copy the 'Current web app URL' and post this in your form/script action

    4. Insert column names on sheet named 'Data' to match your Storyline variables (case sensitive)
    */

    var SCRIPT_PROP PropertiesService.getScriptProperties(); // new property service
    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("k ey"));
    var 
    sheet doc.getSheetByName(SHEET_NAME);
    var 
    headRow e.parameter.header_row || 1;
    var 
    headers sheet.getRange(111sheet.getLastColumn())
    .
    getValues()[0];
    var 
    nextRow sheet.getLastRow() + 1// get next row
    var row = [];
    for (var 
    i in headers)
    {
    if (
    headers[i] == "Timestamp")
    {
    row.push(new Date());
    }
    else
    {
    row.push(e.parameter[headers[i]]);
    }
    }
    sheet.getRange(nextRow11row.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("key"doc.getId());


  • #2
    try this:
    https://haxe.org/

    Comment

    Working...
    X