Forum Discussion
Moodle issue reporting the student name
- JoeFrancisCommunity Member
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.
- ChrisPim-f7a22bCommunity Member
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
- PhilMayorSuper Hero
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.
- ChrisPim-f7a22bCommunity Member
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
- PhilMayorSuper Hero
Thanks Chris, wow 10 years feels like a long time.
var newName = newName.replace(/[undefined ]+/g, "");
Not tested that at all, but it should replace all of the occurrences of undefined with nothing.
- ChrisPim-f7a22bCommunity Member
OK thanks - can the line go anywhere in the code? Sorry to be a bit slow but not a Javascript programmer
- PhilMayorSuper Hero
Good question
var lmsAPI = findLMSAPI(this);var myName = lmsAPI.GetStudentName();var array = myName.split(',');var newName = array[1] + ' ' + array[0];var newName = newName.replace(/[undefined ]+/g, "");
player.SetVar("newName", newName);
That is where I would put it - ChrisPim-f7a22bCommunity Member
Ok thanks Phil!
- ChrisPim-f7a22bCommunity Member
Hi Phil,
That code resolved the variable as ChrsPm
Looks like it stripped out 'i' and a space?
- PhilMayorSuper Hero
sorry brain dead today trying to be too clever
var newName = newName.replace("undefined ", "");