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