Moodle issue reporting the student name
Feb 15, 2022
By
Chris Pim
Hi,
We have some courses created in Storyline 360, exported as SCORM packages and hosted in Moodle
We use the Javascript code below which ran on enter slide and always worked just fine..
Now, instead of the variable 'newName' referenced in a text field reporting 'Chris Pim" as it should, it reports "undefined Chris Pim"
I suspect a Moodle update has caused this bug but have no idea how to remedy it - can anyone help?
---------------------------------
var player = GetPlayer();
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);
}
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);
11 Replies
What is returned in Storyline if you populate the Storyline variable newName with the Javascript variable myName? I commented out lines 3 & 4.
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
//var array = myName.split(',');
//var newName = array[1] + ' ' + array[0];
player.SetVar("newName", myName);
I'm curious that it wasn't returning "Pim Chris", as the correct SCORM format for cmi.core.student_name is last name, first name and middle initial, with last name and first name separated by a comma.
Hi
I am not sure...but it seems to give the names correctly - but where could the 'undefined' element be coming from - any ideas?
Chris
Had this in sum total where a middle name was defined, but wasn't defined in most cases, I just added a line to search the string for undefined and remove it.
I agree with Joseph run it without the split and see what is coming back.
Hi Phil - thanks. Do you have that code snippet?
BTW you were the first Storyliner that reached out and helped me nearly 10 years ago now...eternally grateful for that help!
Chris
Thanks Chris, wow 10 years feels like a long time.
Not tested that at all, but it should replace all of the occurrences of undefined with nothing.
OK thanks - can the line go anywhere in the code? Sorry to be a bit slow but not a Javascript programmer
Good question
player.SetVar("newName", newName);
Ok thanks Phil!
Hi Phil,
That code resolved the variable as ChrsPm
Looks like it stripped out 'i' and a space?
sorry brain dead today trying to be too clever
Yes that works!
many thanks Phil!
Chris