Forum Discussion

SasikumarMuruga's avatar
SasikumarMuruga
Community Member
2 months ago

Get the Learner Name from Saba Cloud

Hi, We are using Saba Cloud and I am trying to get the Student Name from SCORM package using SL360 but I am not able to get that information. Here is the code I am using it

var player = GetPlayer();
var lmsAPI = parent;
var name = lmsAPI.GetStudentName();
player.SetVar('name', name);

 

Can you please help to get this information?

  • HI @Sasikumar Murugan

    I am not familiar with Saba Cloud and their LMS - But it may be that you need to add extra code to find the lmsAPI object.

    When working with different LMS platforms, the way you access the LMS API may vary. Sometimes, the API object is directly available in the current window. This is more likely when the content is launched in a new window or tab...

    ...If the content is embedded in an iframe, the LMS API might be available in the parent window (as you are assuming).... if there are several levels of embedding of iFrames you might need to go to the 'top' of that hierarchy to find the LMS API...

    ...If the content is nested within multiple frames or iframes, the API might best be found by recursively checking each parent window up to a certain depth. Something like this:

    function getAPI() {
    var theAPI = null;
    if (window.parent && window.parent != window) {
    theAPI = findAPI(window.parent);
    }
    if (!theAPI && window.opener) {
    theAPI = findAPI(window.opener);
    }
    return theAPI;
    }

    function findAPI(win) {
    var theAPI = null;
    var maxTries = 7; // Maximum depth to search for the API
    while ((win.API == null) && (win.parent != null) && (win.parent != win) && (maxTries > 0)) {
    maxTries--;
    win = win.parent;
    }
    if (win.API != null) {
    theAPI = win.API;
    }
    return theAPI;
    }

    var lmsAPI = getAPI(); // This will attempt to locate the LMS API

    Hope this helps - please mark as 'helpful' if it does :)

    • SasikumarMuruga's avatar
      SasikumarMuruga
      Community Member

      Thank You Mark! I tried this and still its not providing the results and I did put an alert and I am able to get the Object from lmsAPI call but when I try that var name = lmsAPI.GetStudentName() is not giving any results.

  • I got the results using the below code

    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 name=lmsAPI.SCORM_GetStudentName();
    var nameArray=name.split(',');
    var firstName=nameArray[1];
    var lastName=nameArray[0];
    player.SetVar('first_name',firstName);

     

    Thank You So much!

  • BrendaParedes's avatar
    BrendaParedes
    Community Member

    Hi Sasikumar, I'm experiencing a similar issue. I used the code below & it works in Scormcloud and Litmos but not in saba.


    let player = GetPlayer(); let myName = lmsAPI.GetStudentName(); let array = myName.split(','); let newName = array[1] + ' ' + array[0]; player.SetVar("lmsName", newName);

    Instead of returning the student's name it's printing random numbers and letters. Was that your case as well? I'm going to try using the code you provided above.

  • JoeFrancis's avatar
    JoeFrancis
    Community Member

    I am using this Javascript in Cornerstone SBX (aka Saba) to retrieve the learner's UID and name, which I then parse into first name/last name:

    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 lmsStudent_ID = lmsAPI.GetStudentID();
    player.SetVar("lmsStudent_ID", lmsStudent_ID);

    var lmsStudent_Name = lmsAPI.GetStudentName();
         var nameArray = lmsStudent_Name.split(", ")
        var niceName = nameArray[1] +" "+nameArray[0];
         player.SetVar("lmsStudent_Name", niceName);
         var txtFirstName = nameArray[1];
         var txtLastName = nameArray[0];
         player.SetVar("txtFirstName",txtFirstName);
         player.SetVar("txtLastName",txtLastName);

    With the following variables declared in Storyline:

    • lmsStudent_ID
    • txtFirstName
    • txtLastName

    If you want to declare a variable in Storyline named txtStudentName and populate it with what lmsStudentName retrieves, that may help with troubleshooting.