user
@joefrench
SheetsSet working; however, SheetsGet is not working
Hello, I have had success getting the SheetsSet to function; however, I'm having trouble getting the SheetsGet to function. And, I'm not sure what I'm doing wrong. Would you be able to take a look at my Captivate file? Thanks for your help!
reply
Reply
user
@support
If you are referring to the action on slide 4: the issue there is that the loading script occurs right before SheetsGet. Internet is not instant, it takes time for the signal to travel to the server and back, even if that time is a fraction of a second. JavaScript, however, does not wait for it to finish before proceeding to the next line (SheetsGet). So you have a situation when it tries to use the function before it loads. You can address this in two ways:

1. Load the widget on an earlier slide so that by the time the user gets to this slide, the widget will already have loaded.
Or
2. Place the SheetsGet lines inside the loading function after "window.stencilsheets=!0" + comma, so it'll be ...window.stencilsheets=!0,SheetsGet('YesSum','yesResultsAllClassSum'),SheetsGet('NoSum','noResultsAllClassSum') - haven't tested this one, but in theory it should work.
reply
Reply
user
@joefrench
Ok, excellent. That sounds like good news to me, as I was planning to add more content (and time) between the survey prompt and the survey results. And, it also sounds like my hunch to fire off and call the widget early was also correct. In fact, what if I call the SheetsGet almost immediately to populate the variables in Captivate and then perhaps call SheetsGet again to update the data? It's not vital to update the data in this case, but would that work or would it cause an error (the second calling of SheetsGet)?

Thanks so much for your help!
reply
Reply
user
@joefrench
Hmmm.... actually, it's still not populating the variable in Captivate, even when I'm calling the SheetsGet widget on the very first slide. That should be plenty of time, right? I fear I might be doing something wrong that allows the variables in Captivate to populate. In the developer console, it says that SheetsGet is not defined--is that expected?
reply
Reply
user
@support
No, it's not expected. Do you have the updated ctpx file?

Regarding the other question - placing SheetsGet after SheetsSet should be okay because all they do is add tasks to the widget queue. The queue itself is programmed to wait until the previous Set/Get finishes before sending the next one. So while JavaScript will execute them right away without waiting, the second call will just stay in the queue until the first one clears.

However, if the second call relies on a variable that will change as a result of the first call, then these two should be separated because JavaScript will place the task into the queue based on the variable value at the time of execution, not sometime later.
reply
Reply
user
@joefrench
My other question was about using SheetsGet and then the same SheetsGet (Not SheetsSet) later in the presentation--I'm guessing the same queue applies. Thank you for that!

Here's the updated file:
reply
Reply
user
@support
Two SheetsGet or two SheetsSet back to back is not an issue as they can't be in conflict with each other.

In the cptx file you just sent, it's the same action as earlier just moved to a different slide. Maybe I wasn't clear in my first message: using SheetsGet/SheetsSet right after the JavaScript code that load the widget will result in JavaScript calling SheetsGet before the widget is loaded, so there is no SheetsGet to call at that point. You can address this in two ways:

1. Load the widget on an earlier slide, then call SheetsGet on a later slide (so you know the widget will already be loaded by the time the user gets to the later slide).

2. Place the SheetsGet lines inside the initialization code (see my original message for the example).
reply
Reply
user
@joefrench
Gotcha. I did misunderstand. Now, I have those two bits of code separated (on slides and time) yet it still doesn't produce the results I'm hoping for. To clarify, the large chunk of code is on slide 1 (only) and the SheetsGet is on slide 4 as an On Enter (slide) action (the large chunk of Javascript code is not repeated here on slide 4).

What I haven't tried is associating the SheetsGet with a button instead of the On Enter action. I feel like it shouldn't matter, but.... Thoughts on that? Thanks once again for your continued support!

Here's the latest Capt. file:
reply
Reply
user
@support
Joe, what is the result you're trying to accomplish? As the user enters the course, all of their cells in the spreadsheet are blank. So calling SheetsGet for any variable will return a blank value no matter what. What am I missing?
reply
Reply
user
@joefrench
I'm hoping to create a "survey" experience where students answer one yes-or-no question, and that's the SheetsSet, which functions just fine. The purpose of that is to tally the number of yes responses and no responses.

Then, later in the presentation, we want to display the results from the entire class (or all results captured so far) by including the total number of yes responses and the total number of no responses. This is where I was hoping to use SheetsGet.
reply
Reply
user
@support
You can do that, just prior to calling SheetsGet, do SheetsSet to write a formula to the cell firs, then call SheetsGet to read the result.
reply
Reply
user
@joefrench
Ok, immediately, I won't know how to write Javascript to create a formula in Google Sheets. I was hoping to have the formula in Google Sheets do that math and then I could call the result of the formula through SheetsGet. I suppose it won't work that way?
reply
Reply
user
@joefrench
Ok, I think I see now. The widget captures and reads one users data, which is on one row of the Google Sheet.
reply
Reply
user
@joefrench
Ok, I figured it out. I didn't realize it would be as easy as inserting the formula into SheetsSet(column header, 'formulaHere');

That's awesome!

I was initially thinking that I would have to write some crazy Javascript code.

Thanks again!
reply
Reply
user
@support
Yes! Glad you were able to figure it out.
reply
Reply
user
@support
Thank you again for contacting us. While I have you, can I ask you to leave a rating and write a few words about what you were able to build or what problem you solved with our widgets? Here's a link you can use: https://g.page/r/CR0bTP7bM3YHEAg/review This will really help us to continue providing this service to learning developers, including you.

And of course, feel free to reach out if you need additional support or have more questions.

Thank you very much, we appreciate your business!
reply
Reply