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
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:
... 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).
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!
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:
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!
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;
Click on new variable;
Fill out the dialogue that pops up exactly as shown;
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 ..
YESSSSSSSSS!!!!!!
Thank you so much :) :) :)
Any time :-)
Thank you!!!
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?
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!
Thanks for the info and, again, for the code!
Curious how you could modify this to include full name... That could be useful in creating a certificate screen with name, date, title of the training, etc.
Hi Brett,
That's an easy one!
Use the code below and store the variable in certName.
Thanks very much for the quick reply. I kind of guessed it would be easy (for you) but not being a JS coder I wouldn't have a clue. Looking forward to giving this a try.
No worries Brett! I just cut and hack until it kinda works!
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!
Is your certificate one of the slides in Storyline or did you create it outside of SL? If it's a slide in SL:
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.
My certificate was created in JavaScript using WordPress editor. I now included the JavaScript with my results slide. Please see the attached. Whatever you can do to help me. I have spent several hours trying to get this done but no luck. Thanks so much..
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.
Put a button (label it Print, if you'd like) on your certificate screen to execute the following JS:
window.print();
It's not beautiful but should print the window for you.
I did as suggested by Brett but when the certificate prints, it prints the button label as well. I'm still trying to figure out how to print my certificate of completion. Somebody should please help me! Thanks.
Hi Kayode
What about having a trigger When timeline starts show Layer 1, and have the Print button on Layer 1. See if the certificate prints the layers as well or just the base.
Alternatively see if you can put two triggers on the button of Hide button and Print ... perhaps see how that goes.
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
Hi Kayode
There was no attachment, however as a "best case suggestion" remove the Print button and just have a trigger to Print when the timeline starts. This at least would get rid of the Print button being on your certificate.
There is a Print Result option when I added a trigger. This trigger only prints the result and not the certificate.
Thanks,
Kayode
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.