Forum Discussion

LauraMillion's avatar
LauraMillion
Community Member
11 days ago

Java Script pulls name from Blackboard Grade Center

I created a certificate in Storyline for compliance training. The Storyline file is published as a SCORM package and uploaded to Blackboard. Within the Storyline is a Java Script code that pulls the name of the user from the Blackboard Grade Center. That Java Script code no longer works. I suspect that Blackboard changed something in their database or someplace. This is the script that has stopped working: 

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

 

Attached is an image of the Storyline slide showing where the first name and last name should appear. (Note, the system date still works correctly). 

Does anyone know if there is a new variable name or what code I can use for this? I am a novice using Java Script.  I can't tell you how I came across this original script either. We can't use the option where the user types in their own name. Anyone can type in anyone else's name. We need the name of the person that has taken the training to be automatically printed on the certificate with no ability to change.

Thanks in advance.

Laura

2 Replies

  • JoeFrancis's avatar
    JoeFrancis
    Community Member

    I see a couple of potential issues. JavaScript executes code line-by-line, starting at the top. "lmsAPI" isn't defined, because what it refers to hasn't yet been defined. And "name" hasn't been defined because the function it refers to hasn't yet been defined.

    GetStudentName() and GetStudentID() are functions built into Storyline, which refer to the SCORM data elements cmi.core.student_name and cmi.core.student_id respectively.

    This is the code I've been using to retrieve the learner's name and then parse it, along with his/her UserID.

    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("txtStudentName", 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
    • txtStudentName

     

  • LauraMillion's avatar
    LauraMillion
    Community Member

    OH MY GOSH! Thank you so much. That worked. We need this certificate for compliance training and we were panicking that it wasn't work. Thank you! Thank you! Thank You!