Forum Discussion

AnikaGlischi352's avatar
AnikaGlischi352
Community Member
3 years ago

Adding user name to training using JavaScript

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

  • JoeFrancis's avatar
    JoeFrancis
    Community Member

    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

    • AnikaGlischi352's avatar
      AnikaGlischi352
      Community Member

      Thank you so much!! Really appreciate this.

      I tried it in Scorm cloud and it came out fine (Welcome Anika!)

      However, the LMS did not return the name. :(

      Should all LMS get results? Or can it be that this one does not return this data?

  • 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.


  • 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.

    • AnikaGlischi352's avatar
      AnikaGlischi352
      Community Member

      It looks like that did the trick! :) 

      It displays "default user" in ScormCloud as well as in my LMS.

      Now I just need to know how to add the user's name again....  Sorry, I am JavaScript illiterate.... :)

  • Well thats clearly not correct then... the default user is the value when it doesnot recognize a LMS... i add some conditions in the Javascript to check the URL... let me quickly fix that...

     

    Republish this version and retry on your LMS

  • Thank you!! 

    It is now displaying my first and last name in Scorm Cloud. But in the LMS it is showing "Welcome undefined Anonymous!" 

  • mmmm... thats no good... apparently there is something in CrossKnowledge thats preventing this. Let me build in some checks so we get some more info.

  • 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.

  • Oh my....

    So sorry, to take all your time on this.... (but also glad for your help!)

    I will do some more research and I also connected with CrossKnowledge to see if they can help on their end. 

    I got a lot of info, though! Many thanks!!!

  • 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.

    • AnikaGlischi352's avatar
      AnikaGlischi352
      Community Member

      Ok, I will test that!

      Thanks again for your time and wisdom!!! :)

    • AnikaGlischi352's avatar
      AnikaGlischi352
      Community Member

      I did upload it into a course and test it in my regular user account, though....

      Do you think the Single Sign On could interfere here?

      • MathNotermans-9's avatar
        MathNotermans-9
        Community Member

        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.