49 Replies
Matthew Bibby

Add an Execute JavaScript trigger that includes the following:

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

Then add text variables called first_name and last_name to Storyline and use variable references to display them as needed.

Publish and test in the intended environment.

That should do the trick.

Michael Anderson

Create a javascript trigger and use some code like this:

var player = GetPlayer();
player.SetVar("NameOfYourStorylineVariable", variableValue);

Let us know if you need more help than this. There is more sample code here: https://articulate.com/support/article/javascript-best-practices-and-examples

Marcia Dougherty

Matthew, I don't know if you have any other suggestions.  I have been trying to get the JavaScript trigger to work using the script you provided, but with no luck.  When I run it live in the LMS I am not getting an error, just nothing is being returned.   Not sure what I am missing.  Would it matter if I am using a demo version of 360?  Are some features disabled?

Matthew Bibby

Using the demo version of 360 shouldn't matter.

What LMS are you using Marcia? And are you publishing to Flash, HTML5 or both?

There have been some changes to the way that SL360 handles the lmsAPI in the HTML5 output as discussed here.

I suspect that this updated code may work for you:

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

Let me know if that helps. 

Marcia Dougherty

Hi Matthew,

Thanks for the quick response. The script you gave me did not do the job, but the link to the discussion did. I am publishing to SCORM 1.2 and using HTML5 with Flash. This is what worked for me. Thanks everyone.

var player = GetPlayer();

function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;

// all done if no parent
else if (win.parent == win) return null;

// climb up to parent window & look there
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + ' ' + array[0];
player.SetVar("newName", newName);

Thanks,
Marcia
-----------------------------------------
The information contained in this email is confidential and is intended solely for the use of the person identified and intended as the recipient. If you are not the intended recipient, any disclosure, copying, distribution, or taking of any action in reliance on the contents is prohibited. If you receive this message in error, contact the sender immediately and delete it from your computer. Personal e-mails are restricted by PSECU policy. As such, PSECU specifically disclaims any responsibility or liability for any personal information or opinions of the author expressed in this email.

Kayode Arowolo

This JS is already giving me a headache. This might be a very simple fix for someone. All I need is to pull a student's name from Blackboard and insert it in a completion certificate slide that I have created. Please see the attached certificate with the script I'm using (created by Matthew Bibby). I am using Storyline 3. Any help will be greatly appreciated.

Matthew Bibby

I'm not sure why the print function isn't working. Maybe try putting the print button on the base layer rather than on a separate one?

Also, rather than having the user press a button to insert their name, you could change your Execute JavaScript trigger so that it runs when the slide timeline starts.

Aaron Max Abramowicz

Publishing Using HTML5 on Cornerstone LMS, This code was sort of working but giving me a duplicated name...
By modifying it slightly I was able to get rid of the duplication and have the full name display.

I was hoping to separate the first and last name, but (after 22 attempts) I've decide to settle with it working this way.

The on-slide reference display variable is: %newName%

and the JS code was as follows:

var player = GetPlayer();

function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;

// all done if no parent
else if (win.parent == win) return null;

// climb up to parent window & look there
else return findLMSAPI(win.parent);
}

var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[0];
player.SetVar("newName", newName);

Thanks for the starting point!

Ashley Terwilliger

Hi Azza, 

Are you having an issue with the code that Aaron shared? 

It looks like he used it with HTML5, but perhaps it's the difference in browser or LMS. You could also look at testing it in SCORM Cloud to further narrow down where the issue could be. 

Lastly, when you're launching it in IE - do you see an error message or a different behavior than expected? If you can share a bit more detail that may be just the hint the community needs to help with this custom code.