Forum Discussion
Pulling first name from LMS
Hi all - I'm wondering if anyone might be able to put together a step-by-step guide as to how to set up a variable / javascript function for this? (i.e. pulling a user's first name from the LMS).
I've read through this discussion (https://community.articulate.com/discussions/articulate-storyline/retrieve-lms-user-name-as-variable) but I'm very green and have had no experience with javascript functions (and only basic variables).
Any help for dummies would be amazing.
Thanks,
Sal
46 Replies
- SallyMilfordCommunity Member
Hi again Matthew - curly one for you. Any way to remove any punctuation from a last name?
i.e. O'Bryan > obyran
Taylor-Smith > taylorsmith
(I'm looking to arrive at a reference(s) which creates a username which is <firstinitial><surname>
i.e.
Carrie O'Bryan > cobryan
Thanks,
Sal
- LeslieFosterCommunity Member
Matthew
Can I confirm what settings you had when you published it. I have been on this all day and if i set it to publish with flash or flash as fallback...it works. If I set to html5 only...it fails.
I have tested on scormcloud and in moodle.
- LeslieFosterCommunity Member
Further testing make it more bizarre (using ScormCloud):
Publish with HTML5 or HTML5+flash fallback - does not work
Publish with Flash or Flash+HTML5 fallback - works if you publish to scorm, but not if you publish to tincan
As I am using scormcloud, can I therefore assume that it is a Storyline bug?
- LucioCommunity Member
This should provide the requested results:
var lmsAPI = parent;
var name = lmsAPI.GetStudentName();
var id = lmsAPI.GetStudentID();
var nameArray = str.split(" ");
var firstName = nameArray[1];
var firstInitial = firstName.charAt(0);
var lastName = nameArray[0];
var cleanLastName = lastName.replace(/[^a-zA-Z]/g, "");
var userName = firstInitial + cleanLastName;
var userName = userName.toLowerCase();
var player = GetPlayer();
player.SetVar('first_name', firstName);
player.SetVar('last_name', lastName);
player.SetVar('first_initial', firstInitial);
player.SetVar('email', id);
player.SetVar('username', userName);- SallyMilfordCommunity Member
Thanks Lucio - you're a star :)
Just confirming, I will need the following text variables in Storyline for this to work:
first_name
last_name
first_initial
email
username
?
Thanks,
Sal
- LucioCommunity Member
Hi Sally,
Yes those are the variables required in SL.
Lucio
- SallyMilfordCommunity Member
Thanks Matthew and Lucio - this is working great :)
Except in one instance, when calling to display the last name, a random comma appears after it.
This is what I have used:
var lmsAPI = parent;var name = lmsAPI.GetStudentName();var id = lmsAPI.GetStudentID();var nameArray = str.split(" ");var firstName = nameArray[1];var firstInitial = firstName.charAt(0);var lastName = nameArray[0];var cleanLastName = lastName.replace(/[^a-zA-Z]/g, "");var userName = firstInitial + cleanLastName;var userName = userName.toLowerCase();var player = GetPlayer();player.SetVar('first_name', firstName);player.SetVar('last_name', lastName);player.SetVar('first_initial', firstInitial);player.SetVar('email', id);player.SetVar('username', userName);This is how the reference appears on the slide:
Username: CORP\%first_name%.%last_name%
This is how it appears when published:
Username: CORP\Sal.Milford,
Surname is definitely just Milford in the LMS. Any ideas?
Thanks,
Sal
- LucioCommunity Member
Ooops my bad, sorry! Good catch Matthew!!
- ChrisPimCommunity Member
Nothing works if publishing HTML5 only in Moodle.
Anyone found a fix yet?
- LeslieFosterCommunity Member
Chris...
Ah.....so it is not just me having a problem!
I also have if html5/flash fallback when used in noodle.
Les
- LucioCommunity Member
Perhaps a stupid question, but do you have javascript enabled on your browsers?
- LeslieFosterCommunity Member
If I publish courses in flash or flash +html5 fallback...then everything works. If I publish in html5 only or html5 + flash fallback....nothing works, no data is pulled from Moodle. Given it works in flash with the same browser configuration, then I assume javascript is working in the browser. I have tested in Chrome, Edge and Firefox and always get the same result in all browsers.
- ChrisPim-7dc640Community Member
Yes as Leslie says. JavaScript is enabled. It's a definite problem with the script, 360 and Moodle. In storyline 2 the same script works properly.
- LucioCommunity Member
I'm still on SL2 and will be for a while. Sorry I can't help!!
Related Content
- 7 days ago
- 7 months ago
- 3 years ago