Explore the community Forums Lectora Lectora Questions & Answers Trigger Lectora event from JavaScript

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #398445 Score: 0
    Profile photo of Stan Miller
    Stan Miller
    Member
    beginner
    intermediate
    LUC16 Attendee
    wise owl
    contributor
    curious george
    friend finder
    LUC17 Attendee
    40 pts
    @smiller7502

    We need to track completions of a third-party survey from within our LMS. (Don’t ask.)

    I’ve built a simple title with an HTML extension that displays the survey inside our e-learning skin. The survey is designed to go to a URL on our domain after it’s submitted, specifically because this causes the iframe’s onload event to fire a second time. I’ve added JavaScript to the extension so that when the onload event fires for a second time, the extension is hidden by setting .style.display=”none”; That reveals a text box previously covered by the extension saying you’re done.

    This works beautifully — except that I cannot figure out how to set course completion.

     

     

    objLyr.hide(); won’t work with the HTML extension, and apparently doesn’t trigger Lectora’s On Hide event anyway.

    So: How can I trigger a Lectora event when the JavaScript hides the extension?

    #398448 Score: 0
    Profile photo of Zachary Liquorman
    Zachary Liquorman
    Member
    beginner
    intermediate
    friend finder
    profile
    curious george
    wise owl
    contributor
    picture perfect
    8 pts
    @zliquorman1276

    We need to track completions of a third-party survey from within our LMS. (Don’t ask.)

    Oh god. I feel your pain, I need to track survey completion data from a survey I created that will be hosted on a third-party’s LMS…

    To your question, this sounds less like triggering the Lectora event than it is triggering the LMS’s completion event. Are you publishing your title as a SCORM package to be hosted on your LMS? If that’s the case, then this is simple and you just need to trigger the specific event for that SCORM version. I’ve had to do this before as well.

    See this SCORM run-time reference: https://scorm.com/scorm-explained/technical-scorm/run-time/run-time-reference/

    If it’s a SCORM 1.2 package, you need to trigger the cmi.core.lesson_status event, which you can do manually via Javascript directly, or by using the pre-defined variable in Lectora (and creating some event/action trigger to fire which then sets the variable = “completed” or one of the other valid statuses listed in the run-time reference).

    In my case when I did this, I had the user click a button to “submit survey and test results” which then triggered the submission of those relevant variables, and then set the completion status (assuming they passed the assessment) before taking them to a pass (or fail) page with a button to exit or retake the assessment if they failed.

    What you can do is: After the survey has been submitted and the HTML object is hidden revealing the “You are done!” message, modify that message. Have it tell the user something like “click here to complete the submission”, and have a button for the user to click, and tie a Lectora action to that click event to trigger the above completion status event.

    #398452 Score: 0
    Profile photo of Stan Miller
    Stan Miller
    Member
    beginner
    intermediate
    LUC16 Attendee
    wise owl
    contributor
    curious george
    friend finder
    LUC17 Attendee
    40 pts
    @smiller7502

    Yes, it’s SCORM 1.2.

    If it’s a SCORM 1.2 package, you need to trigger the cmi.core.lesson_status event, which you can do manually via Javascript directly,

    How did you get a course to publish by setting the completion in JavaScript? When I try that, Lectora says, “Assignable Unit … is missing a scored Test or a Modify Variable action for either AICC_Lesson_Status or AICC_Score.” I suppose I could add a test that nobody sees and set the score on that, but that’s pretty hacky.

    and creating some event/action trigger to fire which then sets the variable = “completed”

    That’s the rub. As noted, I don’t want the user to have to do anything else; they’ve already submitted the survey, so seeing a button that says “Submit Survey” would be confusing, and as noted, we know from experience that some users will simply close the course window. I’m looking to set completion status when they submit the survey. I can already detect when they submit the survey, and need to be able to fire an action from that.

    #398455 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    355 pts
    @timk

    I think the easiest way would be to create an action group with your completion actions. Then run the action group with javascript:

    runGroup_og1234()

    Replace og1234 with the html name of the group.

    #398457 Score: 0
    Profile photo of Zachary Liquorman
    Zachary Liquorman
    Member
    beginner
    intermediate
    friend finder
    profile
    curious george
    wise owl
    contributor
    picture perfect
    8 pts
    @zliquorman1276

    How did you get a course to publish by setting the completion in JavaScript? When I try that, Lectora says, “Assignable Unit … is missing a scored Test or a Modify Variable action for either AICC_Lesson_Status or AICC_Score.” I suppose I could add a test that nobody sees and set the score on that, but that’s pretty hacky.

    Sorry, I think it sounded like I was saying this was done externally without any Lectora variables. I meant that you could trigger Lectora actions via Javascript directly or otherwise just use Lectora actions to trigger what you need.

    So, like Tim K said, you could create an action group which modifies the completion variables. For example, when the onload event fires for the second time, you have Javascript run (e.g. runGroup_ActionGroupName() )

    That action group would contain (at the very least) an action to modify the variable AICC_Lesson_Status (which is just Lectora’s name for the underlying variable it is referring to, the SCORM 1.2 variable cmi.core.lesson_status), and set it equal to one of the statuses in that run-time reference I posted before (e.g. completed).

    As long as the AICC_Lesson_Status is being modified in the Lectora content, it doesn’t care about the score (in SCORM 1.2 the score of an assessment is directly tied to the lesson status, but not all LMS’s are set up to recognize this which is why I would play it safe and modify the AICC_Lesson_Status variable instead of modifying the AICC_Score variable).

    To summarize: 

    In Lectora, you can group together at least two actions, and call it something like completion_group. Create whatever other actions you feel are necessary in the group, but make sure to at the very least have the action Modify Variable set to target AICC_Lesson_Status with type Set Equal To with value completed.

    Then, in your Javascript, when your second onload event fires, you call the function runGroup_completion_group(). This will set the completion status of the course to completed and your LMS should update accordingly.

    #398459 Score: 0
    Profile photo of Stan Miller
    Stan Miller
    Member
    beginner
    intermediate
    LUC16 Attendee
    wise owl
    contributor
    curious george
    friend finder
    LUC17 Attendee
    40 pts
    @smiller7502

    <span class=”handle-sign”>@</span>zliquorman1276, I actually do know how to set a course completed. My problem was (note past tense) triggering an action to do so from the JavaScript inside an iframe. As noted in reply to Tim, running an action group from a JavaScript within an iframe doesn’t work because the script doesn’t have access to objects on the parent document.

    However, it does have access to a header script on the page that contains the iframe, and I can call a function in that header script from within the iframe. So:

    1. An action group with actions to hide the iframe, show the “you’re done” message and set the course completed.
    2. A header script with a function that runs that action group. (Thanks for that snipped, Tim!)
    3. A line in the script in the iframe calling parent.function()

    I am intrigued by this line, which could prove very helpful for other situations:

    you could trigger Lectora actions via Javascript directly

    Got a code snippet for that?

    #398461 Score: 0
    Profile photo of Zachary Liquorman
    Zachary Liquorman
    Member
    beginner
    intermediate
    friend finder
    profile
    curious george
    wise owl
    contributor
    picture perfect
    8 pts
    @zliquorman1276

    you could trigger Lectora actions via Javascript directly

    Got a code snippet for that?

    I’m not sure I understand the question. Tim’s snippet above, runGroup_og1234(), is the JS that triggers the actions in Lectora.

    Unless you were referring to something like having JS set a Lectora variable like AICC_Lesson_Status directly instead of using an action group. Which, you could do, but it would result in the error you saw before where Lectora won’t publish the file because it’s not seeing the AICC_Lesson_Status variable being modified by an action/assessment score.

    #398463 Score: 0
    Profile photo of Stan Miller
    Stan Miller
    Member
    beginner
    intermediate
    LUC16 Attendee
    wise owl
    contributor
    curious george
    friend finder
    LUC17 Attendee
    40 pts
    @smiller7502

    OK, I thought you meant that a specific action could triggered directly from JavaScript.

    #398468 Score: 0
    Profile photo of Stan Miller
    Stan Miller
    Member
    beginner
    intermediate
    LUC16 Attendee
    wise owl
    contributor
    curious george
    friend finder
    LUC17 Attendee
    40 pts
    @smiller7502

    Update: It doesn’t work in the LMS, or in SCORM cloud. Console shows “parent.surveySubmitted is not a function”. Works great in every Lectora mode.

    Still open to ideas.

    #398485 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    355 pts
    @timk

    Doesn’t this error just mean that the path to the function is incorrect? If you call the function from within the iframe with the survey, and if you publish with Seamless Play, which brings in another iframe, the function should be one level further up, i.e. parent.parent.surveySubmitted()

    I usually prefer running action groups because it returns the external script back into the Lectora context, but you can use any of Lectoras actions in Javascript directly.

    #398494 Score: 0
    Profile photo of Stan Miller
    Stan Miller
    Member
    beginner
    intermediate
    LUC16 Attendee
    wise owl
    contributor
    curious george
    friend finder
    LUC17 Attendee
    40 pts
    @smiller7502

    Tim K, thanks for sending me down the right path! We don’t use Seamless Play, but you got me thinking about the path instead of about access to the path. As it turns out, I was pointing up too far, and simply calling function() instead of parent.function() got it going. Thanks!

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.