Forum Discussion

SallyMilford's avatar
SallyMilford
Community Member
8 years ago

Pulling first name from LMS

Hi all - I'm wondering if anyone might be able to put together a step-by-step guide as to how to set up a variable / javascript function for this? (i.e. pulling a user's first name from the LMS).

I've read through this discussion (https://community.articulate.com/discussions/articulate-storyline/retrieve-lms-user-name-as-variable) but I'm very green and have had no experience with javascript functions (and only basic variables).

Any help for dummies would be amazing.

Thanks,

Sal

  • Hi Matthew,

    Could you help me with a java script, if I needed to pull in the learners initials from their first and last name from the LMS? (Example, I need Andrew Ford to appear as AF)

    Thanks!

    • KevinBrake-09e3's avatar
      KevinBrake-09e3
      Community Member

      This may work, untested... let me know:

      // Capture first initial from a variable
      full_name = full_name.str.charAt(0);
      first_name = first_name.str.charAt(0);

      or maybe this one:

      // Capture first initial from first and last name
      var last_name = array[2];

      first_name = first_name.substring(0, 1);
      last_name = last_name.substring(0, 1);

       

  • DarrenNash's avatar
    DarrenNash
    Community Member

    Does this work for all LMS systems or specific ones? I am trying this with CSOD and it does not work.

    • JoeFrancis's avatar
      JoeFrancis
      Community Member

      This works with LMS' which adhere to AICC/SCORM standards, and are populating the field where the user's name is expected (retrieved using cmi.core.student_name) with the user's full name. The prescribed format is Last Name, First Name, Middle Initial, with the last name and the first name separated by a comma. Spaces in the name must be honored.

  • I am struggling with using JavaScript to capture the user's first and last names from the LMS (Vector Solutions). They store the user name as "Firstname, Lastname, Middle". This is the code I am using but it is not working. I was able to insert the date using JavaScript.

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

  • Lucio's avatar
    Lucio
    Community Member

    Hi Glenda,

    From what I see in your code, you must declare the "player" variable before making the API call.

    Try this:

    var player = GetPlayer();
    var StudentNameIn = lmsAPI.GetStudentName();
    var array = StudentNameIn.split(',');
    var StudentName = array[1] + ' ' + array[0];
    player.SetVar("StudentName", StudentName);

    If you wish to split the name in two variables, you may use your approach instead of "StudentName".