LMS Course Name JavaScript Action

Aug 08, 2023

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);

26 Replies
Craig Bunyea

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.

Joe Lloyd

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);

Craig Bunyea

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);

Phil Mayor

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);

 

Craig Bunyea

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.

Joe Lloyd

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

Phil Mayor

Hi Craig, I was replying to Joe he had syntax errors in his code and wasn’t setting the player so nothing would come back.

The console should be your friend to find errors, I just find it odd that the course name is available to pull directly although ESR is odd as it uses oracle and a transition layer between the course and the LMS

Sent from my iPhone

Joe Lloyd

ESR is a very strange system and never quite works or behaves as a standard system should....

I used to use Lectora Online which was very easy as this could basically pull down the API setting straight from the course itself.

but with Articulate there isn't that option.... i am not 100% how the console works and what i need to do in there.... i am literally just starting a degree in software engineering so hopefully in a few years this will all be much easier and make sense to me but for now i am but a fish out of water 🤣

Joe Lloyd

iat the end of each course there is a certificate, and instead of creating a separate certificate for each course i was trying to create a project variable that could copy and past the value on the certificate.

i would then be able to save the story line page as a block template to past in to all my courses within articulate RISE and therefore save time.

i know an alternative method would be to just type in and create a separate story line package for each course but i have over 100 course and was hoping for an easy win :)

Craig Bunyea

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.

Joe Lloyd

Hopefully this shows what you need ?

the value that it returns is correct and the current JS i am using to modify the project variable is what was supplied previously;

var player=GetPlayer();
var externalCourseID = classroomName;
player.SetVar("CourseName", externalCourseID);

Craig Bunyea

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

Craig Bunyea

So much like lmsAPI.GetStudentName(); fetches the variable myName, there should be a function within lmsAPI that can retrieve the className.   Use your console and type "lmsAPI." and scroll to all the Get functions, there are likely many.   Just guessing, it could be lmsAPI.GetClassroomName();   but everything's case-sensitive of course.
That is what you'll add to the right of =

Craig Bunyea

Well it's entirely possible that multiple APIs are running in your environment, so the method you're using to invoke GetStudentName() in fact might not include any reference to what you'd think is a GetClassName(). When desperate I've gone to the Console's sources tab and explored what look like API scripts and searched for some variable reference I know exists. Storyline includes scormdriver.js when publishing for a SCORM LMS.

Joseph Francis

Sam Coulson listed all of the available functions in LMSAPI.js several years ago. These functions correspond to their AICC/SCORM data elements. While AICC did have a data element reserved for course title called course.title, SCORM did not carry that data element over.

Since that element doesn't exist, you can't even query the LMS through the API using the SCORM function GetValue(element:CMIElement) : string, because, again, course.title doesn't exist in the SCORM dataset.

SCORM Run-Time Reference Guide