Forum Discussion
LMS Course Name JavaScript Action
Morning all,
I am hoping someone will be able to support me here, I am trying to have a JavaScript action that will set my "CourseName" the code i am using is as follows;
var player=GetPlayer();
var course=player.GetVar("CourseName");
player.SetVar("CourseName");
I use an LMS and this story-line certificate is embedded in to a Rise package, i have managed to get the Student Name and Date to all pull through from the LMS but i cannot get the Course Name to do the same (example of student name is below incase this is needed)
var player = GetPlayer();
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;
else if (win.parent == win) return null;
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var LMSName = array[1] + ' ' + array[0];
player.SetVar("newName", LMSName);
- CraigBunyea-23dCommunity Member
This may be more dependent on your LMS API, than Rise. Since there is a function called GetStudentName() that you are successfully using, what are the functions associated with the course or learning object? Student names are stored in SCORM as well, so those are pretty easy to retrieve no matter which API is in play. With the Cornerstone LMS there are a few (very few) global variables we can employ in HTML. One trick I use is to launch the course, open the Dev tools > Console and start typing Get.. With the API already loaded, and context typing, you can see the API classes available - maybe Course-something is there.
- JoeLloyd-17dcfeCommunity Member
Thank you for your reply Craig,
i have managed to follow this and found the function "classroomName" which returns the right value, however i am now unsure as to what the java script code would be to get this a function to then change the variable named "CourseName" to "classroomName"
i tried the following but didnt appear to work..... Player.SetVar ("CourseName", classroomName);
- CraigBunyea-23dCommunity Member
I'll try to help. In your first post you declared a variable (not in your SL project though) simply called course (let's give it a little customization), However you produced the value you wanted in the console, that goes to the right of 'var externalCourseID ='
// the scope of externalCourseID is local only to this javascript snippet
var externalCourseID = classroomName(' **someUniqueParameter**');
// CourseName is a Project Variable
player.SetVar("CourseName", externalCourseID); - JoeLloyd-17dcfeCommunity Member
apologies for the constant back and fourth (im new to JS coding & coding in general)
i have tried the following but still not pulling through results
var externalCourseID = classroomName
player.SetVar("CourseName", externalCourseID);im unsure where to go from here
- PhilMayorSuper Hero
Are you checking the console for errors? I am sure you must be getting some.
Course name is not defined in the scorm standard, so using the LMSAPI is unlikely to work.
In the code you posted last you definitely have a syntax error and need to dd the line var player=GetPlayer();. Even then you need to know what you are connecting to to pull the variable.
var player=GetPlayer();
var externalCourseID = classroomName;
player.SetVar("CourseName", externalCourseID);- CraigBunyea-23dCommunity Member
Phil, I wasn't assuming he was using any SCORM API because unfortunately you're right about the SCORM spec. What I was going from was Joe writing "and found the function 'classroomName' which returns the right value". So however that value was returned via the console that he said he could use, he should replicate that to the right of the externalCourseID =
Joe, employing the function classroomName (however you did that in the console) requires a pair of trailing parentheses and likely some quoted parameter inside those parens. Copy/paste that text to the right of
var externalCourseID = classroomName('some parameter');
and see what happens. Of course make sure your single/double quotes are never stylized, curled, etc. What LMS are you working with? Their API documentation is probably online and we might be able to research that function a little more.
- JoeLloyd-17dcfeCommunity Member
Thank you so much all for the support…..
The LMS I am using is ESR (Electronic Staff Records) which is an NHS system used by most organisations in some capacity in the UK
as previously mentioned i have managed to get the java-script to work for finding the users name and copy and paste over a project variable which is grabbing that information from the system. And ive also managed to get the date working (however i know this doesn't need to come from the LMS this can be based on the system date)
Thank you all for this support i really appreciate it
- CraigBunyea-23dCommunity Member
It looks as though I'd need to be a customer to access ESR documentation, but it sounds like since you are likely running this Rise course within the ESR environment, classroomName() is a function that 'lives' at the parent/global level, which is why it's working in your browser's console window. If that classname is itself an ESR global variable, is that what you plugged into classroomName( ) to get a result? Javascript in a Rise trigger should be able to access that same 'parent' function. Maybe send a screen shot (redact stuff if necessary) of your console with classroomName returning what you wanted.
- JoeLloyd-17dcfeCommunity Member
- PhilMayorSuper Hero
var player=GetPlayer();
var externalCourseID = classroomName();
player.SetVar("CourseName", externalCourseID);should work what does it show in the console
- JoeLloyd-17dcfeCommunity Member
- CraigBunyea-23dCommunity Member
Thanks for that, it provides some context, but I'm not sure now how to help. I can see why you thought to just use classroomName as an assignment to some internal Rise variable, but to Rise, that is just a random string of letters at that point. Rise needs to know the var is from outside its project. With Storyline, they have a script that employs the versions of SCORM API, so I use that to retrieve user inputs on relaunch (see attached) and even 'force' completion if needed.
SCORM2004_CallSetValue('cmi.completion_status', 'completed')
var player = GetPlayer();
var newTxt0 = player.GetVar('TextEntry1');
SCORM2004_CallSetValue('cmi.interactions.0.learner_response', newTxt0);
SCORM2004_CallSetValue('cmi.interactions.0.id', 'SurveyQ1');
console.log("INt0 = " + SCORM2004_CallGetValue('cmi.interactions.0.learner_response'));I think you need to hunt for the function in a parent ESR script that looks like ...getValue('classroomName' ) - and add that to the Rise trigger
- PhilMayorSuper Hero
I am out of the office for the next three days so cannot look at some old courses. Are you pulling the name and date into the certificate already in the storyline block if you are the code should be working did you run the last one I posted with opening and closing parentheses?
- JoeLloyd-17dcfeCommunity Member
- JoeLloyd-17dcfeCommunity Member