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);
28 Replies
- JoeFrancisCommunity Member
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.
- CraigBunyea-23dCommunity Member
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.
- JĂĽrgen_Schoene_Community Member
the LMS stores Scorm data and Scorm data are ONLY learner data - name, state ...
the "name of the course" does not belong to it
- CraigBunyea-23dCommunity Member
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 =- PhilMayorSuper Hero
But if it resolves directly in the console you should be able to use as is.
Sent from my iPhone
- JoeLloyd-17dcfeCommunity Member
very very strange..... i am just not sure if i have set it up correctly but if the code is there and is being instructed and initiated the exact same as the other codes then it should be working in theory but for some reason it just isnt.....
- PhilMayorSuper Hero
LMSSPI doesn’t normally have course name suspect there is a ERS API as well
Sent from my iPhone
- JoeLloyd-17dcfeCommunity Member
- 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
- 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
- LizAndersonCommunity Member
Hi Craig! Sorry to reply to an old comment, but I'm curious about the method of "forcing completion" that you mention.
I need to use either a SL Block or a Custom Code Block in Rise to send completion for a successful pre-test. However if the pre-test is not passed, I need to fall back on sending completion with 100% viewed.
I tried using your SCORM2004_CallSetValue code, with no luck -- hoping you can provide more insight on this?
- CraigBunyea-23dCommunity Member
Which specification are you publishing to? If it were SCORM2004, then executing that SCORM2004_CallSetValue(... ' completed') should trigger a Completed status in a LMS.
If you published to SCORM1.2, then simply aSCORM_SetCompleted("completed");
worked for me (testing a dummy course in SCORM Cloud). As I'm only familiar with Storyline, that has a Built-in variable called Quiz.ScorePercent. Do you have a trigger working on your results page which takes a passing score and send any message to the browser (ex., a javascript:alert()?) If you use your browser DevTools, the SCORM APIs are searchable - just hunt around.
- JoeLloyd-17dcfeCommunity Member
- PhilMayorSuper Hero
var player=GetPlayer();
var externalCourseID = classroomName();
player.SetVar("CourseName", externalCourseID);should work what does it show in the console
- 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
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.
- PhilMayorSuper Hero
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