HELP! SCORM 2004 v3 and Javascript
Jun 24, 2016
Hi everyone.
I am having an issue (either Cornerstone, CSOD LMS, or the javascript) where I can't retrieve the users name from the LMS.
I have created a trigger on the first slide of my SL2 course with the js that communicates with CSOD to retrieve the name and places this in a variable.
It works perfectly in SCORM 1.2 but the javascript doesn't work in SCORM 2004 v3. I am not really sure what the problem can be. Do I need a different script syntax when using SCORM 2004?
I need to publish in 2004 because I am trying to report on the assessments that I've created in SL2. I need to know how many people are getting a question right/wrong. TinCan isn't an option for me because Cornerstone wants to charge extra $$ for us to use the API. (not sure if this was a contract item, but beyond my control)
Any help is greatly appreciated. The syntax below is the JS being successfully used in SCORM 1.2. I believe this code came from someone on the boards or elsewhere - I apologize that I don't recall the name to give credit.
//grab the LMS object
var lmsAPI = parent
//ask the LMS object to get the name
var rawName = lmsAPI.GetStudentName();
//the name comes very formal "Last, First"
//we will fix that by sticking the name into an array
var nameArray = rawName.split(",")
//get the first name
var firstName = nameArray[1];
//get the last name
var lastName = nameArray[0];
//now we grab the Articulate player
var p = GetPlayer();
//finally we set our Articulate vars to our js values
p.SetVar("firstname",firstName);
p.SetVar("lastname",lastName);
THANK YOU SO MUCH FOR HELPING!!
10 Replies
Please use lmsAPI.SCORM2004_GetStudentName() - it is the function available in SCORM 2004.
Thank you so much Kamil.
I will try this in just a moment.
Do you happen to have a link that shows what functions changed from 1.2 to 2004?
THANK YOU AGAIN!
If you use SL or SL2, you can check it in lms folder and file SCORM2004Functions.js
Good morning Kamil.
Thanks so much for your help. I made the change to the javascript as you suggested but unfortunately, I am still getting 'null' as my name. I am posting the new code as well. When I've published to the LMS and take the course, it will not post the learners name.
//grab the LMS object
var lmsAPI = parent
//ask the LMS object to get the name
var rawName = lmsAPI.SCORM2004_GetStudentName();
//the name comes very formal "Last, First"
//we will fix that by sticking the name into an array
var nameArray = rawName.split(",")
//get the first name
var firstName = nameArray[1];
//get the last name
var lastName = nameArray[0];
//now we grab the Articulate player
var p = GetPlayer();
//finally we set our Articulate vars to our js values
p.SetVar("firstname",firstName);
p.SetVar("lastname",lastName);
Any other suggestions will be so much appreciated.
Thank you!
Walt
Just an update. I have tested this new code in SCORM Cloud and it works. On CSOD, it displays null.
Another update...
I added your code from another post...
var player = GetPlayer();
var lmsAPI = parent;
var myName = lmsAPI.SCORM2004_GetStudentName();
alert("my name "+myName);
And the alert message popped up with my name as (firstname lastname) {does that make a difference}
Thanks for your help Kamil
Glad that Kamil was able to assist you here Walt, and thanks for sharing the code in the event that it helps another user who comes across this forum discussion.
Nice that you were able to solve your problem. It means that SCORM2004 shows student name in different way. Congrats :)
Is there any where I can look that has all of the different functions and explains them. I want to explore what I can do with API's and if I can have the LMS tell Storyline if the user has completed this course for courses that are recurrent training.
Hey Andrew!
Check out this article on JavaScript Best Practices and Examples. While Javascript is outside our wheelhouse, our Java-savvy community members can point you in the right direction.
This discussion is closed. You can start a new discussion or contact Articulate Support.