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
Przemysław Hubisz

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

David Rosenfeld

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.

David Rosenfeld

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?

 

Jeremy Usher

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.

 

OWEN HOLT

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.

OWEN HOLT

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);

David del Carpio

Thank you so much for your help! I was able to get it work with the following:

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 myName = lmsAPI.GetStudentName();
var array = myName.split(' ');
var newName = array[0];
player.SetVar("fname", newName);
Alexa Yacteen

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

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);
David del Carpio

I haven't tried SCORM 2004 3rd Edition but I am using Cornerstone and the following pulled both first and last name.

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 myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[0];
player.SetVar("newName", newName);
OWEN HOLT

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.

Alexa Yacteen

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.

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[0] + ' ' + array[1];
player.SetVar("newName", newName);
Sam L

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. 

 

let SD = window.parent;
let player = GetPlayer();
let email = player.GetVar('TextEntryEmail');
let strResponse = email;
let strID = 'emailResponse';
let strDescription ='this_is_for_email';
let blnCorrect = true;
let strCorrectResponse = strResponse;
console.log(strResponse)
submitScorm(strID,strResponse,blnCorrect,strCorrectResponse,strDescription);
function submitScorm(strID,strResponse,blnCorrect,strCorrectResponse,strDescription){
if(strResponse ===''){
return;
} else {

SD.RecordFillInInteraction(strID,strResponse,blnCorrect,strCorrectResponse,strDescription, 1, 1, 'fill-in-example');
}
}

This discussion is closed. You can start a new discussion or contact Articulate Support.