Getting student name from Moodle

Jun 16, 2022

Is there any way to capture the student full name from Moodle and to pass it into Storyline360? I would like to show it in a SL slide and then use the same variable in a PDF document that I would like the students to download automatically after clicking a button. 

I saw some solution (very old though and I fear they worked in Flash times only) but none seems to work in testing. 

I am very 'green' with Javascript so it is possible I do something wrong. Is there any recent solution that work? 

I would like the moodle users to launch the scorm, and see their name on a slide immediately (without them to be forced to type it in an input field) and then also pass this to a PDF that downloads automatically when they click on a specific button. The PDF shall carry the same name captured earlier. 

Thanks for anyone that can help.

Cheers

Andy

10 Replies
Joseph Francis

Let's start with retrieving the user's name from Moodle and displaying it. The Javascript you would use is:

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 lmsStudent_Name = lmsAPI.GetStudentName();
     player.SetVar("lmsStudent_Name", lmsStudent_Name);

Create a new variable in Storyline called lmsStudent_Name and insert it as a Reference into a Text Box.

Nedim Ramic

Hi Andrea,

GetStudentName() and GetStudentID() are both SCORM functions. These functions are available in Moodle all the time when a course is published to SCORM and uploaded to Moodle. GetStudentName() will most likely show your learner's name, and GetStudentID() will show your learner's email address registered in the system. To display it in SL, create one or two balnk text variables in SL: "studentName" and "studentID". Insert it as a reference into a text box. Create "Execute Javascript" trigger with the code below: 

GetPlayer().SetVar('studentID', SCORM2004_GetStudentID())
GetPlayer().SetVar('studentName', SCORM2004_GetStudentName())

I assume you are using SCORM2004 standards to publish your course. Hope this help. 

Joseph Francis

GetStudentID(), which maps to cmi.core.student_id, retrieves whatever an organization decides to populate into field. While an email address may appear in that field, it is neither a requirement nor should it be expected. You are just as likely to find an Employee ID or other unique student identifier in that field. There are no fields in the SCORM reference specifically designated for email address. 

SCORM Run-Time Reference Guide, SCORM 1.2

Nedim Ramic

Hi Joseph,

That's correct. My organization can decide to populate the "Username" field (required) with the learner's email address. It all comes down to personal preference whether the admin wants the learners to log in with an email address or with another unique ID. However, whatever you populate the "Username" field in Moodle with, it is what you will see when you call 'GetStudentID()" function. The same goes with the first name and surname. Both are mandatory fields during the student enrolment process. By calling "GetStudentName()" function, both the first name and surname will show in "surname, first name" format. See attached screenshot.

Andrea Borsoi

Dear Joseph and Nedim,

Thank you both for the help!! I learned so much from you. Joseph your code works perfectly; I have tested it in Moodle (Var Showing) with a single slide made with Storyline360 (Var Showing 2 with Triggers attached too) and it does work. On launching it shows my name. Super. I will be forever grateful and I am now studying the code, so I understand what you did. Big learning and big big help. I owe you coffee or beer :-). 

Thanks also Nedim for your additional inputs. I am really grateful, the learning is so great. 

I think the previous (failed) attempt was also due to SCORM 1.2 and not SCORM 2004. Would the code not work in 1.2? It was also a different code anyway and being ignorant I am not yet at the point where I can discern how to adapt any code I find in forums. Maybe I will try and see, what happens in SCORM 1.2. I am getting more experimental :-) 

Now I am going to try to import the same Var into a PDF (I use Scribus, an open source DTP to create it) and make the PDF automatically download on clicking the button you see in the slide (empty for now) with another JavaScript code (I used one in the past and I am going to try to remember how I did it - it was from other useful entries in this forum).

We want users to click on a button (vs. completely auto download on Timeline starting trigger) cause the document is a legally binding statement for employees (it's a course on sexual misconduct in the workplace) and we want to avoid that people use name of fantasy (or make mistakes typing) that then go into the document. It's a sort of compromise between positive action and automation, but the SME decided this is good enough. 

You helped me a lot and so a big thanks! Now on with the printing/downloading....and self-studying JavaScript. I must say that I see more and more how useful it is.

Greetings from Germany! 

A