Solution for Articulate Storyline xAPI LRS Actor JavaScript

Dec 02, 2022

I had been trying to figure out how to get the learners name from the LMS to automatically populate into the LRS Actor publish settings via the JavaScript template feature.  After many unsuccessful attempts and tweaking of my JS, I was finally able to get it to work using the below JavaScript.  Just wanted to share as I was finding this frustrating and was about to give up.  The below code works for me within ScormCloud and Cornerstone with an external Vervacity LRS.  Thanks and hope this is useful!

 

function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;

// all done if no parent
else if (win.parent == win) return null;

// climb up to parent window & look there
else return findLMSAPI(win.parent);
}


function getActor() {
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
return {
"objectType": "Agent",
"account": {
"homePage": "https://url.com",
"name": myName
}
};
}

Be the first to reply