Forum Discussion
How to access xAPI/Tin Can LMS variables in JavaScript
I have been trying to extract the user's name from the LMS (Docebo). But when it's published to xAPI I can't get it to work.
I tried the code in this thread, and other code, and I always get the console message: "actionator::exeJavaScript - this.execUserJs is not a function"
Scott and Nandhakumar, are you able to retrieve the name when published to xAPI?
here is a short script to parse to xAPI start url for the actor name
function parseName( inURL ){
const urlParams = new URLSearchParams(inURL.split("?")[1]);
var name = "unknown";
if( urlParams.has("actor") ){
var actor = JSON.parse( urlParams.get("actor") )
if( "name" in actor ){
name = actor.name[0];
}
} else {
console.error( "no 'actor' in url: ", urlParams );
}
console.log( "name: " + name );
return name;
}
var url = window.location.href;
var name = parseName( url );
GetPlayer().SetVar("name", name);
this work e.g. on Scorm Cloud
- RobertWebbe-4043 years agoCommunity Member
Wow, that is good news!
As you say, it works perfectly in Scorm Cloud. On our LMS (Stream LXP from Learningpool) it only states the first initial of my first name. I've checked the URL form Scorm Cloud and our LMS and these are the differences:
https://cloud.scorm.com/sandbox/content/courses/NYQLJL20DW/GetLearnersNameFromLMSfd69a70d-fa7b-4a60-a365-c21cd51cc12e/0/index_lms.html?actor=%7B%22name%22%3A%5B%22Robert%20Webbe%22%5D%2C%22account%22%3A%5B%7B%22accountServiceHomePage%22%3A%22http%3A%2F%2Fcloud.scorm.com%22%2C%22accountName%22%3A%22NYQLJL20DW%7Crobert.webbe%40vodafoneziggo.com%22%7D%5D%2C%22objectType%22%3A%22Agent%22%7D&endpoint=https%3A%2F%2Fcloud.scorm.com%2Flrs%2FNYQLJL20DW%2F&auth=Basic%20OjRlNzk1ZTU4LWQ1MDAtNDIyMi04Zjc1LTAyMzJiMWFjYjU0NQ%3D%3D&content_token=a025fb1d-2c75-4851-a658-31ed6ab9564d&externalRegistration=L4dGVbJhbQIJiyF6qq9THUfRi-N54jrZWQRLCtfcWqN0qWCgFYOt5gzGyymZdqPjbNeY93w1-YDaGi7G6PpQC3f1T-6VGlSqiC9LV5nhwfdbgf-CoRgcXqkDtJzNz1s&activity_id=urn%3Aarticulate%3Astoryline%3A5f7Ku7j0hV7®istration=8b731e71-19da-44e2-a1f7-b9b27fc1e493&externalConfiguration=62aEfcbopf-tVvu2eBkxA87cOpHhc5tITFcaJS8wssHNIOjNbQ8Gp9-0fh303END15H_wc2Uq4a3TYtc5pBljilllruO2y-3&grouping=urn%3Aarticulate%3Astoryline%3A5f7Ku7j0hV7&content_endpoint=https%3A%2F%2Fcloud.scorm.com%2Flrs%2FNYQLJL20DW%2Fcontent%2F&width=988&height=744&left=466&top=0
https://content-nlv-eu-central-1.curatr3.com/launcher/index.html?url=https%3A%2F%2Fcontent-nlv-eu-central-1.curatr3.com%2Fresources%2F1762%2Fget-learners-name-from-lms_1687252656%2Findex_lms.html%3Fendpoint%3Dhttps%253A%252F%252Flauncher-curatr.learninglocker.net%252Fcontent%252Flaunch%252F0301bfd8-c319-43d6-9066-7d855bcb6a0b%252FxAPI%252F%26auth%3DBasic%2520LS0tOi0tLQ%253D%253D%26activity_id%3Dhttps%253A%252F%252Fjunkyard.curatr3.com%252Fxapi%252Factivity%252Fresource%252F863792%26actor%3D%257B%2522mbox%2522%253A%2522mailto%253Arobert.webbe%2540vodafoneziggo.com%2522%252C%2522objectType%2522%253A%2522Agent%2522%252C%2522name%2522%253A%2522Robert%2520Webbe%2522%257D%26registration%3D494b54d0-9ed5-4f2d-8a98-7f0bb2dbe12b
My knowledge of this not sufficient to make it work for our LMS. Do you know how I can get it to work? Many thanks in advance! 🙏
- Jürgen_Schoene_3 years agoCommunity Member
try
function parseName( inURL ){
var name = "unknown";
var outerParams = inURL.split("?")[1];
var urlParams = new URLSearchParams(outerParams);
var innerParams = urlParams.get("url").split("?")[1]
var urlParamsTwo = new URLSearchParams(innerParams);
if( urlParamsTwo.has("actor") ){
var actor = JSON.parse( urlParamsTwo.get("actor") )
if( "name" in actor ){
name = actor.name;
}
}
console.log( "Name: " + name );
return name;
}
var url = window.location.href;
var name = parseName( url );
GetPlayer().SetVar("name", name);result: "Name: Robert Webbe"
- RobertWebbe-4043 years agoCommunity Member
Unfortunately the variable is not filled with my name, it's empty.