Forum Discussion

SamuelBarton's avatar
SamuelBarton
Community Member
21 days ago

Grassblade is not reporting q17 of my assessment as answered

Grassblade is not reporting Q17 of my assessment as answered. Q17 is a custom drop-down with 5 layers, but underneath is a freeform Pick One. So 5 points are not being sent to GrassBlade. When testing on Storyline, all marks add up to 32, as they should. When testing on LMS (LearnDash xAPI) marks add up to 27. Help would be very much appreciated, thanks. 

JS:

var p = GetPlayer();

// --- read inputs ---
var pos1 = (p.GetVar("Q17_Pos1") || "").toString();
var pos2 = (p.GetVar("Q17_Pos2") || "").toString();
var pos3 = (p.GetVar("Q17_Pos3") || "").toString();
var pos4 = (p.GetVar("Q17_Pos4") || "").toString();
var pos5 = (p.GetVar("Q17_Pos5") || "").toString();
var score = Number(p.GetVar("Q17_Score")) || 0;

// --- xAPI statement ---
var statement = {
  verb: { id: "http://adlnet.gov/expapi/verbs/answered", display: {"en-US":"answered"} },
  object: {
    id: "http://yourdomain.com/storyline/q17",
    definition: {
      name: { "en-US": "Q17. Hierarchy of risk control (dropdowns)" },
      description: { "en-US": "Learner selected 1–5 positions for each control step." }
    },
    objectType: "Activity"
  },
  result: {
    response: ["PPE="+pos1,"Eliminate="+pos2,"PreventContact="+pos3,"Reduce="+pos4,"SafeSystems="+pos5].join(" | "),
    score: { raw: score, min: 0, max: 5 },
    success: (score === 5)
  },
  context: { platform: "Storyline with GrassBlade" }
};

// --- helper to find ADL in current/parent/top frames ---
function getADL() {
  try {
    if (window.ADL && window.ADL.XAPIWrapper) return window.ADL;
  } catch(e){}
  try {
    if (window.parent && window.parent.ADL && window.parent.ADL.XAPIWrapper) return window.parent.ADL;
  } catch(e){}
  try {
    if (window.top && window.top.ADL && window.top.ADL.XAPIWrapper) return window.top.ADL;
  } catch(e){}
  return null;
}

// --- retry send until ADL is ready (max ~10s) ---
(function sendWithRetry(tries){
  var ADLref = getADL();
  if (ADLref && ADLref.XAPIWrapper && ADLref.XAPIWrapper.sendStatement) {
    ADLref.XAPIWrapper.sendStatement(statement, function(){
      p.SetVar("Q17_Sent", true);
    });
  } else if (tries < 40) { // 40 * 250ms = 10s
    setTimeout(function(){ sendWithRetry(tries+1); }, 250);
  } else {
    // give up but allow navigation; also expose why for your debug label
    p.SetVar("Q17_Error", "ADL not found in window/parent/top");
    p.SetVar("Q17_Sent", true);
  }
})(0);

 

1 Reply

  • Hi SamuelBarton!

    Sorry to hear you’re having trouble with the assessment on your Storyline file. I’ve opened a support case so one of our Customer Engineers can take a closer look. 

    You’ll get an email from them soon!