Pulling just the First Name in Lectora SCORM courses

sirwise23
sirwise23 Community Member Posts: 442 ☆ Roadie ☆
Hello,

I am trying to seperate the First name and last name from the AICC_Student_Name Variable.

I have found instructions here but they don't seem to work for me.  When I publish The page is out of whack.  Last time I saw instructions published was 2013.  I'm wondering if something is slightly different in Lectora 16 and maybe that's the issue.

Thanks.

Comments

  • jvalley4735
    jvalley4735 Community Member Posts: 1,357
    Can you share the instructions?  I'd love to see how it was structured and why it would be different now.  I'll also ask around because I'm not 100% sure on this one.
  • sirwise23
    sirwise23 Community Member Posts: 442 ☆ Roadie ☆
    This was posted in 2013:


    Separating first and last names.

    It can be done in three steps:

    1.
    Create a textfield that’s initially invisible
    Add an action
    On: Page show
    Action: Change content
    Target: This object
    Value: VAR(AICC_Student_Name)

    2.
    Create two variables
    -> lastname
    -> firstname

    3.
    Add an action on page level

    On: Show
    Action: Run JavaScript
    Javascript:
    var username = VarAICC_Student_Name.getValue().split(“, “);
    Varlastname.set(username[0]);
    Varfirstname.set(username[1]);
  • timk
    timk Community Member Posts: 1,227 ✭ Legend ✭
    That code should work correctly, it only contains a combination of issues coming from different versions of forum software used in the community ;-)

    The correct code is:
    var username = VarAICC_Student_Name.getValue().split(",");
    Varlastname.set(username[0]);
    Varfirstname.set(username[1]);

    Tim
  • timk
    timk Community Member Posts: 1,227 ✭ Legend ✭
    Sorry, actually the correct code is:
    var username = AICC_Student_Name.getValue().split(",");
    Varlastname.set(username[0]);
    Varfirstname.set(username[1]);
  • sirwise23
    sirwise23 Community Member Posts: 442 ☆ Roadie ☆
    That was it. Thanks Tim.

    There should not be a VAR in front of AICC_Student_Name

    Once the VAR was gone the page loaded right up.

    Thanks again.
  • JessicaE
    JessicaE Community Member, Lectora® Accessibility Group (LAUG) Member, eLearning Brothers® Partner Posts: 7 ☆ Roadie ☆
    Hello! I've tried this code out but it's not working for me. Even though I followed the steps and put in the most recent set of code from @timk, the LMS is still only displaying lastname, firstname in the text field. It isn't separating the name and then hiding the last name. Is there anything else I can try? I noticed this code is from 2016, would something have changed about Lectora Online since then?
  • andrew-robertson
    andrew-robertson Community Member Posts: 286 ☆ Superstar ☆
    Hi @JessicaE, could you package your course (ZIP or RAR) and share it? It'll be easier to see what you are doing.

    We've used this similar code to personalize our elearning course on corporate security where we say don't use your corporate email - instead of simply having @company.com, we actually took their LastName, FirstName and made it read [email protected] Small little things like that are the proverbial sprinkles on the ice cream.
    Andrew R.
    Developing content since 2010 using a mixed bag of tools.
  • Euan
    Euan Community Member Posts: 2 ☆ Roadie ☆
    I'd just been looking at old forum posts for this recently as well - after trying a few methods and trying to understand how it worked, I've found a method that works well!

    What I felt was missing in some of the step-by-steps was the importance of making sure your variables are referenced in the course before they're used - my JS errored because variables weren't defined.

    Below is how I got this to work nicely - I've got it in a demo Lectora file as well so let me know if you want me to package it up.

    I find this set of instructions can be used on any level of your course - so you can run it on the first page, or just have it running every time a page loads. The important thing is if you're using a version of Lectora that doesn't update a variable value live on the page (so only presents the value it was at on page load), you'll need to use a change content action to present your newly split name as the JS command will have run after your page load.

    Step 1
    Create variables for how I'd like the name to look (in my case I want to split the variable into First Name and Last Name so I've got options for Informal and Formal presentation of the name.

    These are the options I went with in my example:

    firstname
    lastname

    Step 2 - this is so the variables are referenced as the course opens and values set
    Create a text box and put all three variable names into the text box.

    (Create Text Box > Double Click Text Box > Select Properties > Select Variables > Select your variable from the drop down)

    Put all of the variables in there:

    - firstname
    - lastname
    - AICC_Student_Name

    You can put this text box off canvas and hidden but make sure you have one so it defines the variable values in the courses first instance of opening.

    Step 3
    Create an Action > Run Javascript

    Input this code into the JS box:

    var name = AICC_Student_Name.getValue().split(",");

    Varlastname.set(name[0]);

    Varfirstname.set(name[1]);

    Set delay for action: 0.1 (so your file will populate the text box before trying to run this code)

    Note
    If you want to use different variable names from firstname and lastname simply replace this text Var[myvariablename]

    Step 4
    If you are referencing VAR(firstname) or VAR(lastname) on the same page as this action you're running, you will need to run a change content action to update the variable value if using a version of Lectora that doesn't automatically update this later than the page being loaded.