Pulling data from Moodle using Javascript

Pulling data from Moodle using Javascript

by Abhishek Mukherjee -
Number of replies: 1

I have already pulled user name (first name & last name) from Moodle in SCORM 1.2 package (built with Articulate Storyline 2) using this JS code below :


var player = GetPlayer();

var myName  = lmsAPI.GetStudentName();

var array  = myName.split(',');
var newName = array[1] + '  ' + array[0];

player.SetVar("newName", newName);

//myName = player.GetVar('myName');

//player.SetVar("newName", newName);


In the code above, lmsAPI.GetStudentName() is used to retrieve student's name from Moodle.

I am trying to retrieve other data specially the email id from Moodle. How can i do that ? What should i replace lmsAPI.GetStudentName() with to get the email id in my SCORM 1.2 course ? What does Moodle call the email id field ?

Moodle version : 2.6

Average of ratings: -
In reply to Abhishek Mukherjee

Re: Pulling data from Moodle using Javascript

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Unfortuantely the SCORM datamodel doesn't provide for much flexibility around this - the only 2 variables passed related to the student identity are "student_name" and "student_id" -

 the "student_id" field for SCORM 1.2 packages is currently configured to pass the username:
https://github.com/moodle/moodle/blob/master/mod/scorm/datamodels/scorm_12lib.php#L134

If you are using e-mail in the username field you might be able to just use that. Alternatively you could change $USER->username to $USER->email and see if that works - make sure you backup the files before making any changes though.