Get preferred name rather than legal name from LMS using javascript

Jun 06, 2023

Does anyone know how to edit this javascript to pull a learner's preferred name from the LMS rather than the legal 'first name' field? Learners who have changed their gender and their preferred name, but not their legal name, are still seeing their old name in our courses. All our other systems use the 'preferred name' field.

 

var lmsAPI = parent;
var name = lmsAPI.GetStudentName();
var nameArray = name.split(", ");
var firstName = nameArray[1];
var lastName = nameArray[0];
var player = GetPlayer();
player.SetVar('first_name',firstName);
player.SetVar('last_name',lastName);

6 Replies
Sandeep Gadam

Hi Rebecca, try the following code:

var lmsAPI = parent;
var preferredName = lmsAPI.GetPreferredName();
var nameArray = preferredName.split(", ");
var firstName = nameArray[1];
var lastName = nameArray[0];
var player = GetPlayer();
player.SetVar('first_name', firstName);
player.SetVar('last_name', lastName);

Let me know if that worked for you!

Rebecca Evens

hi, this did not work, presumably because preferred name is not on the list of api's for SCORM 1.2: SCORM Run-Time Reference Chart for SCORM 1.2 and SCORM 2004

I have tried revealing the full 'student name', and the field only includes first name and last name, and I cant see any other API that is specified by SCORM.

 

Jürgen Schoenemeyer

on Scorm Cloud you get with "lmsAPI.GetStudentName()" for the learner "John Doe"

  •  Scorm 1.2: "John Doe" (cmi.core.student_name*)
  •  Scorm 2004: "D, J" (cmi.learner_name**)

for Scorm 2004 (on Scorm Cloud) your script should be the result

  • firstName = "J"
  • lastName = "D"

for Scorm 1.2 (on Scorm Cloud)  you can change your Javascript

var nameArray = name.split(", ");
var firstName = nameArray[1];
var lastName = nameArray[0];

to

var nameArray = name.split(" ");
var firstName = nameArray[0];
var lastName = nameArray[1];
  • firstName = "John"
  • lastName = "Doe"

you should check your LMS whether it behaves in the same way, there seems no definition in Scorm how a name is formated

* format "CMIString (SPM: 255)"
** format "localized_string_type (SPM: 250), RO)"

Joseph Francis

Not sure what LMSAPI.js file you're looking at, but there is no such function as "GetPreferredName," as there is no counterpart in SCORM's data model. The only function related to the learner's name in LMSAPI.js is GetStudentName. This correlates to cmi.core.student_name in the SCORM 1.2 data model and cmi.learner_name in the SCORM 2004 data model.

Several years ago, Sam Colson documented the functions available in Storyline. That list can be found here.

Rebecca Evens

Thanks Joseph, I have accepted that the preferred name field in our LMS is not associated with any of the items in the SCORM data model. I'm still confused that my javascript is using the format of the SCORM 2004 model but seems to be working fine when the course is published with SCORM 1.2, but I guess if it's not broke, I won't try to fix it!

Does anyone know of another way to get data out of the LMS and into the course, without using the SCORM data model? I know that we have student data appearing on Sharepoint pages (eg - we have a 'see your required courses page that lists outstanding mandatory courses), but I don't know if this is something simple or really complex to achieve...   

Also, does anyone know if xAPI can pick up more data from the LMS than SCORM? I had a look but I could only see data going INTO the LMS rather than coming OUT of it. Our LMS doesnt support xAPI, but if I could say that upgrading it would help, I at least have something to tell the business!