June 10, 2019
Javascript help!
Comments
(8)
June 10, 2019
Javascript help!
Newbie 1 posts
Followers: 0 people
(8)

I am very new to using Javascript with Captivate, but need some help. I am trying to create script that will check the lesson status and based on that status go to a certain slide. For example, if the course is not completed, I want them to go to slide 2, but if they have completed the course, I want it to go to slide 1 (from my understanding, the first slide in Captivate is actually slide 0). I have been searching around on the internet a lot, but cannot figure this one out! I put below what I have complied based on my googling, but I have no background in Javascript, so there could be some major errors I am not aware of. Any help is greatly appreciated!

LMSGetValue(‘cmi.core.lesson_status’)
if (cmi.core.lesson_status = complete) {
window.cpCmndGotoSlide = 1;
}
else {
window.cpCmndGotoSlide = 2
}

8 Comments
2019-10-30 17:09:08
2019-10-30 17:09:08

nikkid16104379,

I just saw this question….

Looks like you are publishing your Captivate projects to an LMS, and your published Captivate projects are set to use SCORM – Correct?

If you are still needing help with your question, please let me know as I think I could help you.

 

Like
2019-06-12 13:47:04
2019-06-12 13:47:04

Thank you for your help! For the question regarding when the variable will happen, I have a button at the beginning of the course that users will have to click to start. This button has the Javascript code to check the status of the course (incomplete or complete) and then direct them to the correct slide based on the status. Also, I am trying to query the LMS for the completion. When someone first starts the program on the LMS it will register as “incomplete” and then after they have viewed all the slides it will change to “complete”. I have attached the debug log I have been looking at and if you look at line 9, it has the information about the lesson status. Please let me know if you have any other questions, I am very new to coding with Javascript and I appreciate your help!!

Attachment

Like
(5)
>
nikkid16104379
's comment
2019-06-12 14:34:43
2019-06-12 14:34:43
>
nikkid16104379
's comment

Again, I haven’t tried interfacing with an LMS but my concern would be whether or not you are actually grabbing that ‘complete’ or ‘incomplete’ result and bringing it into Captivate.

If I were you, I would want to verify that. I would try to troubleshoot by creating a Captivate variable and set that equal to your query.

So if I make a Captivate variable called  varStatus  for example I would then make a smartshape on the stage with $$varStatus$$ to display the value in the smartshape.

I might place something like this on a button or onEnter to test.

varStatus=(LMSGetValue(‘cmi.core.lesson_status’));

If the code works (it may need tweaking) – the value should appear in the smartshape. If that is all it takes to get that value out of your LMS this might help to see if that value is making it to Captivate. Once you have it in Captivate, it will be easier to work with.

This is at least what my approach might look like.

Like
>
Greg Stager
's comment
2019-06-12 16:48:18
2019-06-12 16:48:18
>
Greg Stager
's comment

Thank you again for your help! Do you know of another way I could do this without interfacing with the LMS? We want to create a table of content slide that will only appear for people who have completed the whole program. I was thinking the only way would be to query the LMS, but if there would be another way I would be open!

Like
>
nikkid16104379
's comment
2019-06-12 17:41:04
2019-06-12 17:41:04
>
nikkid16104379
's comment

Are we talking about a single lesson in a single Captivate file, multiple lessons in a single Captivate file, or multiple lessons across multiple Captivate files?

Like
>
Greg Stager
's comment
2019-06-13 14:12:14
2019-06-13 14:12:14
>
Greg Stager
's comment

There are multiple lessons in a single captivate file that users will complete in one sitting.  At first we want users to watch it all the way through without navigation and then after they complete the course, we want to give them the ability to navigate to a specific lesson when they go back. We were thinking it would be easiest to have a page at the beginning that would include buttons to all the lessons, but we only want people who have completed the course to see this page.

Like
>
nikkid16104379
's comment
2019-06-13 17:47:24
2019-06-13 17:47:24
>
nikkid16104379
's comment

That makes everything a bit less complicated.

I would create a variable that is tripped at the end of all the lessons.

Your opening slide can have an onEnter action that checks the variable.

If the variable is set, we show the buttons and if it is not set, we keep the buttons hidden.

That said – It will work for sure within the same session but I am not sure whether or not your LMS will “remember” that flag if they log out and come back at a different time. You would need to upload to your LMS and try it.

If it doesn’t – it is back to trying to grab the variable from the LMS. The idea is pretty much the same with the difference being whether you utilize your own variable or that of the LMS.

Like
2019-06-11 12:04:08
2019-06-11 12:04:08

Here is my 2¢ on this…

When working with your variable, you would need to use a double equal sign in the if statement. Use a single equal sign for assigning a value and double equal sign for comparing.

For example… let’s make a variable called checkStatus

if (window.checkStatus==1) {
window.cpAPIInterface.gotoSlide(0);
}
else if (window.checkStatus==0) {
window.cpAPIInterface.gotoSlide(1);
}

You will need the logic to set the flag of the checkStatus variable to complete when appropriate as well as some way to trigger this action. Will it be on a button or onEnter?

Notice that I am using a ‘1’ and a ‘0’ for my values rather than words like “complete”. If you do use words like “complete”, you need to have them in quotes or they will be treated like a variable.

if (window.checkStatus==“complete”) {
window.cpAPIInterface.gotoSlide(0);
}

Another question here is… Are you trying to query your LMS? or just looking at the Captivate module itself as the lesson to be completed?

I do not know much about tapping into data for an LMS – never tried doing that but I am not sure it is as simple as using LMSGetValue. Maybe it is – I don’t know. Does your LMS populate that variable with the word “complete”?

This is about as much as I can offer right now without more detail so hopefully it is helpful.

Like
Add Comment