Adding user name to training using JavaScript

Jul 21, 2022

Hello. I am trying to add the user's name to the training via Java Script.  (Bottom of slide 1.2) When I test this in Scorm Cloud, the last name is pulled in (I want the first name, so not sure if there is anything in my code or if that is just how it works in Scorm Cloud)

When I test it in my LMS (CrossKnowledge) I don't get anything. (Only Welcome !  The name is not pulled in.)

Is this due to the LMS then?

I am pretty new to using Java Script here, so not sure what I am doing wrong.

 

I am attaching the test file. The JavaScript is on slide 1.2 at the bottom.

 

Also: is it possible to pull in other data, such as "Employee Location", "Title", etc.

 

Thank you!!!

Anika

19 Replies
Joseph Francis

Line 5: you're creating an array in Javascript, using a space as the delimiter. If your LMS does not store the learner's name using a space as the delimiter, you might not see anything. Try changing the delimiter to a comma and see if your LMS returns something:

var arrayName = myName.split(',');

Line 7: you're extracting the information parked in array element [0] (Javascript, like many programming languages, is zero-based, as in the first position in an array is index 0, not index 1). If you change this line to var newName = arrayName[1], when you run it on SCORM Cloud, you would see the first name.

Because elements like "Employee Location" and "Title" are not in the SCORM data model, you won't be able to extract those from your LMS.

SCORM Run-Time Reference Guide

Math Notermans

All LMS should identify the user and thus be able to store progress. What's the use of a LMS else ;-) But LMS's might tackle Scorm and userdata differently. So first thing to know is what LMS do you use ? Depending on that someone with experience with that LMS might know the way to get it done on that particular LMS.

Rereading your original message it is clear you use CrossKnowledge. I am not sure but checking some documentation on CrossKnowledge it seems they use this on login...
https://developers.crossknowledge.com/api_web_services_list_and_details.html

john.doe

So the separator of name and surname might be a '.'(dot)
You should test that on your LMS.

I suggest you do a test on CrossKnowledge to figure out how the username/surname is composed.

Add this into your code...
console.log("myName: "+myName);

You then get a message like this in your console.
myName: Glischinski.Anika
That will clarify what delimiter to use to split myName into 2 separate values.
I suspect CrossKnowledge uses a dot.


Math Notermans

There is an known issue with LMSApi on some LMS's. As they all implement Scorm somewhat different it might be needed to refer different to the LMSApi on a given LMS.

On ScormCloud that is not happening because the LMSApi is accessible in a direct way. On some LMS's thats not the case. CrossKnowledge might be one of these.

So i always use this function to prevent that and find the LMSApi.

/*
On ScormCloud this function is available. On other LMS's this may not be available,
or you might need to target it differently. Thus adding this function for those cases.
*/
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) {
            return win;
    }else if (win.parent == win) {
        return null;
    }else {
        return findLMSAPI(win.parent);
    }
}

Adding the fixed Storyline. Do try this one on your LMS.

Math Notermans

Doing some research on CrossKnowledge i am now in doubt whether it is a LMS at all. At this page https://www.crossknowledge.com/learning-platform/integration-capabilities/ you can notice several LMS that integrate well with CrossKnowledge... Duh? That means CrossKnowledge as is is no LMS but just a platform connecting with third party LMS's like Docebo, Saba and Cornerstone.  That might explain this. If there is some extra layer inbetween before you connect to your LMS..well that is good to know, because that might need extra code ( parent, root or some like that ) to connect with your LMS. I am not sure whether there are other CrossKnowledge users available in the community, but maybe someone else can shed some light.

Math Notermans

Checking the docx. You are apparently logged in anonymous and not as a student. Do get a test account as student in which you really need to login as student and i guess it will work then. When checking the debug code i see a complex url with a lot of numbers, but in the end its index_lms.html... and the username that gets returned is 'Anonymous'. So the normal steps of splitting them in separate surname and familyname will fail... as the username is 'Anonymous'.

So getting a real test account with proper username will probably fix it.

Math Notermans

I donot know CrossKnowledge well enough. Only thing i can see is that the username that gets sent back is 'Anonymous'. Whether that has to do with SSO or some other setting in CrossKnowledge i cannot tell. Best is test it with a pure student account. If you then still get 'Anonymous' back...well then there is something weird going on on CrossKnowledge side.