Username from an LMS on both Flash and HTML5

Jul 12, 2017

So, I have noticed that javascript has been a little bit unpredictable when deploying dual export (HTML5 and Flash). Particularly when pulling a user's name from an LMS (we use Moodle). 

After trawling through the solutions on here I have put together a frankenstien of a few different solutions that actually works in both HTML5 and Flash (well it does on our system).

Thanks to Knut Jackowski for pointing out an error in the code!

updated 16/04/2018

So ... here you go ...


//find out if html5 version is running

var path = window.location.pathname;
var html5 = path.includes("html5");

if (html5 == true) { //if html5 is running run this script this is where the error was
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];
player.SetVar("newName", newName);

} else { //if html5 isn't running (in other words flash) run this script

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

}

This code tests if html5 is being used (thanks to Matthew Bibby for the great example). If it is then the first block runs ... if not then the second block runs.

I hope people find this useful, this may have been posted elsewhere, but I couldn't find it! 

It's worth noting that this only pulls the first name and you have to create a newName text variable in Storyline!

41 Replies
Michael Bauer

Hi there

I am still struggling with this, but perhaps because I know nothing about Java and may be missing an step that is second-nature to the experts.

If I copy ALL of your text in grey above and set up the trigger like this:

Javascript01

... what else do I need to do?

I created a Text Box that I called NewName and has the text NewName in it ...  not sure what else I need to here. Do I need another trigger or something? All that showed up was the text of NewName on the screen when running through the LMS (SuccessFactors).

John Brindle

Hi Michael,

You need to ensure that the variable name exactly matches the variable name in the javascript. so instead of NewName try newName - javascript is case sensitive. You also need to leave the variable empty (so a text variable, with the name newName and nothing in the value field). 

Other than that, I have only tested this in Moodle and have never used SuccessFactors! 

I hope this works for you!

Michael Bauer

Thanks for your help so far!

Sorry, I really don't understand JavaScript, I just presumed the whole script would change a text box that I titled newName would make it work. If only the world was that simple :)

A few questions:

  • The text box titled newName, what do I put in this? If I leave it blank, the text box disappears
  • You mention "leaving the variable empty" but what variable do I need to make?

I have attached the file, it is probably something really simple that somebody can help with? It may perhaps be that SuccessFactors doesn't pass this information through, however just exploring all options!

John Brindle

I can see where the issue is :-)

First step is to create a new variable with the title newName. You can do this by ...

clicking on the variable button;

Step One

Click on new variable;

Step Two

Fill out the dialogue that pops up exactly as shown;

Step three

Hit OK on all dialogue boxes. 

Now create a text box in your project and type the following into the text box;

%newName%

With your current project set up as it is, when the javascript runs on slide start it should display the first name of the user nicely!

I've attached a project that should work below ..

C Jones

This code saved me loads of time! I couldn't get it to work though with IE 11 / Flash. The code works in this scenario if I remove the if-then-else block that checks for HTML 5; findLMSAPI() is always executed regardless which player is running. Is there any reason why findLMSAPI() should only be called when using the HTML 5 player?

John Brindle

I'm not sure. It worked great in IE 11 with my testing.

It may have something to do with the way the SCORM wrapper works in Moodle (which is the only LMS I have managed to test in). I believe with HTML 5 it runs in an iframe so the script needs to hunt for the LMSAPI by hopping up from the frame to the LMS, whereas the Flash is embedded directly and displays in the LMS page (not as a frame), but this is just a guess from my observations!

 

 

John Brindle

Hi Brett,

That's an easy one!

Use the code below and store the variable in certName.

 var path = window.location.pathname;
var html5 = path.includes("html5");

if (html5 = true) {

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 myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1];
var certName = array[1] + " " + array[0];
player.SetVar("newName", newName);
player.SetVar("certName", certName);

} else {

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

}
Kayode Arowolo

Hello, I am trying to execute the above code to retrieve the registered student names in our Blackboard LMS. This is the scenario: Imagine a student logs in to his/her LMS and is going through this training course after which he/she will print out a certificate of completion that will include his/her registered name in the LMS. The module is created in Storyline 360. I have already created a certificate. How do I retrieve the name from the LMS to print on the certificate. Thanks for your help!

Brett Rockwood

Is your certificate one of the slides in Storyline or did you create it outside of SL? If it's a slide in SL:

  1. Create new variables exactly as described.
  2. On the first slide put a JavaScript trigger that runs when the timeline starts and paste the code John provided above. 
  3. On your certificate slide enter the variable references for the names where you want them to appear. The variable references are the variable names enclosed with percent signs, e.g., %newName% or %certName%.
  4. When the first slide plays the JavaScript trigger will get the name from the LMS and store it for use in the course.
  5. When the user gets to the certificate slide the %newName% and %certName% variables will be replaced with the names pulled from the LMS

If you're trying to get a variable out of Storyline and into another application to create your certificate, that is an entirely different scenario that I have not done before; maybe someone else in the community can help.

Kayode Arowolo

Hello Brett,

I have created a certificate inside Storyline. Please see the attached .Story file. Now what I'm struggling with is: How will I be able to print this certificate on course completion? Please help! I have spent several hours over the past days to get this done and it's not working for me yet. Thanks.

Kayode Arowolo

Thanks for your prompt response to my request. I created a layer and inserted a button labelled 'print certificate' When the certificate prints it prints the button as well. Please see the attached. You will notice that the print shows all the unnecessary fields such as the menu items on the left and it cuts off part of the top.
Thanks 

John Brindle

Hi Kayode,

There are lots of options for printing certificates in Storyline although none of them are supported properly by the software itself (these are all workarounds or hacks).

This article links back to this community and shows 6 ways to try and print a certificate.

You may want to try this method too.

This is a really complex and fairly hit-and-miss way of generating a PDF certificate that is auto-populated. I have tested this several times and difficulty making it work with our projects. You'll have to get used to the PDFmake syntax though to generate a decent PDF. You can pass variables from Storyline to it though to pick up results etc.

Failing that we have yet to find a reliable way to print a certificate from Storyline that renders correctly every time. I believe that Blackboard may have a certificate module, perhaps it would be beneficial to enable conditional unlocking and host the auto-populated certificate separately?

Other than that there's not much more help that I can personally give you I'm afraid. Just search the discussions on here and see what you can find to suit your needs :-)

This discussion is closed. You can start a new discussion or contact Articulate Support.