Cornerstone learner name
Oct 31, 2018
Hi
We've just started using Cornerstone Ondemand as our LMS and have a issue pulling the learner name from the LMS into the course using Javascript, from a SORM 2004 v3 output. I have a script that worked in their sandbox but it doesn't work in the live environment. The script I'm using is;
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.SCORM2004_GetStudentName();
var array = myName.split(',');
var newName = array[1];
player.SetVar("newName", newName);
Would really appreciate some help, so we can get our courses transferred.
Jeremy
25 Replies
Hi Jeremy,
Have you managed to make this work?
Hi Daniel
Not yet, we're a bit stuck as a large proportion of our courses use this and the names are embedded through the courses so not including it would me a fair bit of re-writing.
Hi Jeremy,
I think your script is correct.
By the way, is your Text Entry has its name "newName"?
It should be TextEntry.
player.SetVar("newName", newName);
Hi Jeremy,
I checked it on it looks like Cornerstone returns Name and Surname as an array with Name and Surname ["John Doe"] but it is not split by comma as expected in the formula ["John, Doe"]. So when you try to do this var array = myName.split(',') you get Array with only one item and this part var newName = array[1] return undefined as there is no second position in the array. Can you check it on your side? Please change the old line of code with this: var array = myName.split(' ');
Hope it helps,
Przemek
That would make sense Przemek.
Hi Daniel and Przemyslaw
Problem solved!
Many thanks for your help, this has saved me so much time.
Jeremy
Hi There. I tried this and it worked for Student Name! Thanks for posting.
What function would I use to get the "Username" from Cornerstone? Not the StudentID, or the StudentName....it's an email address in our Cornerstone LMS.
Any thoughts? Thanks!
Hi Dave
As a guess I'd change the line
var myName = lmsAPI.SCORM2004_GetStudentName();
to
var myName = lmsAPI.SCORM2004_GetUsername();
and see what happens
jeremy
Hi Jeremy. Thanks. It turns out you can't grab username via the SCORM functions that are available. That being said!...
I was able to pull in User IDs, but they are DIFFERENT ID #s than what's in our company LMS.
Do you have any insight on that. I'm reaching out to Cornerstone about it as well. My thoughts are that this could be pulling in a Cornerstone generated ID, vs. their Employee ID within the system.
We just learned that it's pulling something called the "Target User ID" - which is in the URL in the browser bar. It's "Cornerstone generated". Why would this SCORM2004 function be pulling that User/Student ID #?
lmsAPI.SCORM2004_GetStudentID();
Is SCORM2004, 3rd edition not the best specification to be using for this?
Hi Dave
I'm no expert on Cornerstone, we're only just finishing implementation, and Javascript, I tend to use what I find on the Articulate forums and tweak a bit. So I don't think I can help any further, with this code.
I have found the API.SCORM2004 call does work with SCORM 2004 3rd edition and it is what Cornerstone have recommended to use.
Hi Dave,
We are facing the same issue on Cornerstone about the Username vs the Employee ID. Did you get any resolution to your problem?
Looking forward to receiving some help here.
Thank You,
Juily
Can someone let me know what I'm doing wrong?
I didn't open your file, however, I am on Cornerstone and am using the following:
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 first = array[1];
var array2 = first.split(' ');
var newName = array2[0] + ' ' + array[0];
player.SetVar("NewName", newName);
Note that some of the code is dependent on HOW your lms admin is storing names. On our prior LMS, it was "First Last". When we first launched Cornerstone, it was "Last,First" [no space]. Now we are at "Last, First" I believe.
The point is that you should test and then adjust as required until you get the right result.
Thank you so much! I tested it various different ways before posting and I couldn't get it to work. I tried using what you provided and I can't get it to work. I appreciate the help!
Scorm 2004 is tricky and known to create issues. I'm guessing that is what you are facing. I wish I had better news. Can you publish with scorm 1.2?
Try something more like this:
var player = GetPlayer();
var myName = parent.API.GetValue("cmi.learner_name");
// You will need to know how names are rendered in your LMS. For me it is First Middle Last so to split into an array, I will split on the spaces between names and the first name will be the first member of the array
var array = myName.split(' ');
var firstName = array[0];
player.SetVar("NewName", firstName);
Thank you so much for your help! I was able to get it work with the following:
Hi Przemyslaw,
I have been having the same issues with the "undefined" message appearing on the certificate. I tried the code below and now the certificate is only pulling the learner's last name from the LMS. Do you have any guidance on what I could be doing wrong? The course is published as SCORM 2004 3rd edition for a Cornerstone LMS.
Any help would be greatly appreciated. Thank you
I haven't tried SCORM 2004 3rd Edition but I am using Cornerstone and the following pulled both first and last name.
You may not be doing anything wrong, it might be a factor of how your organization implemented CSOD. Some companies will store the name as Last, First while others might list it as First Last. I suspect that might be the case with yours since you are splitting on the space (" ").
If that is the case, the First name will be array[0] and the last name will be array[1].
In JavaScript, array member positions begin at 0 for the first member and increase by 1 from there.
Thank you Owen and David.
Owen, would the new code be what I have below? I have tried 7 different variations of this code and have had no luck. The client is eager to get this training launched, but we can't find a solution for the certificate page. Everything worked fine when published to SCORM 1.2, but we had to switch to SCORM 2004 due to the resume feature only working up to 30% in 1.2.
If the user name is already in First Last format, you don't need to split it into an array and recombine it.
Try simplifying the last part of your code to this:
var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.SCORM2004_GetStudentName();
player.SetVar("newName", myName);
Hello,
I thank you for the above code. It worked well in pilot, haven't tried it in production yet. I was hoping to get some help with the following. I am trying to set up an email form and capture the name, email and message and pass it to the lms. I've tested this out in scorm cloud and it looks like it is sending data, however.. when I try to pull a report in Cornerstone for scorm 2004 3rd edition on quiz questions, nothing is reporting. This code came from a course I took and then I modified it.
To follow up. I turned debug on and it is giving me a 406 error and it says
strSCORM2004ErrorDiagnostic=The cmi.interactions.0.latency value of 'P0S' is not a valid timespan
This discussion is closed. You can start a new discussion or contact Articulate Support.