Get the learner's name from LMS Crossknowledge

Oct 28, 2020

Hello,

I need to use on all Articulate Storyline slides of a project the name of the student as it's written in the LMS. So I try to extract the name from the LMS (Crossknowledge).

Actually it seems that it is possible using a trigger with Javascript integrated to the Articulate Storyline project. Crossknowledge told me I need to call from the LMS the variable cmi.core.student_id (nom,prénom) . 

Could you pease help me? Maybe someone has already had the issue?

I try this but it doesn't work :

var lmsAPI = parent;

var Name = lmsAPI.Getcmi.core.student_id (nom,prénom)

Kind regards

Nathalie

7 Replies
Math Notermans

This basically does the trick.
I have the 2 function.. findLMSAPI and getUsersName in my generic function, but you can use them as is in a trigger.

You need to have a custom variable 'newuser' in your title. That will be changed upon receiving the LMS usersname.

Also when testing it on ReviewLink the url changes, you have to know what your LMS gives back exactly and then you can finetune this code as needed.

//some variables needed
var pathArray,nyName,newName;

var player = GetPlayer();

function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) {
return win;
}else if (win.parent == win) {
return null;
}else {
return findLMSAPI(win.parent);
}
}

function getUsersName(){

console.log("getUsersName");

pathArray = window.location.pathname.split('/');
console.log("pathArray[2]: "+pathArray[2]+" | "+window.location.pathname+" | "+pathArray[1]);
//&& pathArray[1] !="review" => true if it is not on Storyline Review, so a real LMS
if (pathArray[2] != undefined && pathArray[2] !="Users" && pathArray[1] != "review" && pathArray[1] != "rise"){
// when published as Scorm 1.2 on a LMS
var lmsAPI = findLMSAPI(this);
myName = lmsAPI.GetStudentName();
var array = myName.split(',');
newName = array[1] + ' ' + array[0];
player.SetVar("newuser", newName);
console.log("pathArray[2]: "+pathArray[2]+" / "+myName+" | "+newName);
// on a LMS
//pathArray[2]: elo.fontys.nl / Notermans,Math M.L.
}else{
// locally testing or not on a LMS
console.log("NOT ON A LMS!, so use a demo user");
player.SetVar("newuser", 'User,Demo');
myName = "User,Demo";
newName = "Demo User";
}
}

getUsersName();

No need to copy paste the code as i attach a working sample.
Do use the browser inspector to check what your getting back.
CTRL+SHIFT+I or F12

Julia Davenel

Hi Math, thanks for your reply.

I just tried it and it works perfectly well in my articulate page!

I have another question.... I'd like the name of the learner to appear when he/she prints the scorm out. Right now, when i try to print and see if my name appears , it says  " 22/03/2021 getUsersNametestprint2004". 

Is there any solution to this?

Many thanks 

Math Notermans

Ah ok, clear now. Basically the print button is the default Storyline one in the player. And when the title is shown.. well it prints all by default. So you can hide the title of the course in the player, so that is fixed then. However i do suspect you want the printout more customized. That is possible, but only with results slides. So if you have a quiz setup, you can print your results slide with a trigger. Im sure its possible with Javascript too, but didnot have the time now to figure that out. There probably already is a solution on the forum to print a page with Javascript somewhere.