Forum Discussion
Creating downloadable pdf files in Storyline - an update on earlier methods
I am late to the party, but REALLY want to pull this off. I am working on a Roles and Actions course that will culminate in a "Now go do it!" kind of sheet. I would love for them to be able to download it. I worked the JS into what I needed(Story attached). I have the document(attached as well). I think all of it looks good. I am publishing to a LMS from Storyline and telling it to create a Zip file. I have put my document ALL OVER the zip file to try to make sure it found the document. When I preview it or load it into the LMS and go through it, when I click the button nothing happens.
Now, interesting fact, I loaded your notes demo in the LMS and in preview from Storyline and nothing happens with it either. SO, I am think my code my be good, but it is not finding a file.
I have also changed the URL for the document to our SharePoint site and that does nothing too.
Help me Obi-Won Kenobi!
PS: I added triggers to fill out what you can see on the screen and then I got smart with the things your can't but are on the PDF and added it to the variable default. :)
Replace the following part of the code with the one below. Ensure that const formUrl = ''; exactly matches the name of the PDF file located in the root folder.
var player = GetPlayer();
Role1 = player.GetVar("Role1") ?? "";
Role2 = player.GetVar("Role2") ?? "";
Role3 = player.GetVar("Role3") ?? "";
Role4 = player.GetVar("Role4") ?? "";
Role5 = player.GetVar("Role5") ?? "";
Role6 = player.GetVar("Role6") ?? "";
Role7 = player.GetVar("Role7") ?? "";
Role8 = player.GetVar("Role8") ?? "";
RolePicked1 = player.GetVar("RolePicked1") ?? "";
RolePicked2 = player.GetVar("RolePicked2") ?? "";
RolePicked3 = player.GetVar("RolePicked3") ?? "";
Action1 = player.GetVar("Action1") ?? "";
Action2 = player.GetVar("Action2") ?? "";
Action3 = player.GetVar("Action3") ?? "";
Body = player.GetVar("Body") ?? "";
Mind = player.GetVar("Mind") ?? "";
Spirit = player.GetVar("Spirit") ?? "";
Heart = player.GetVar("Heart") ?? "";
Time1 = player.GetVar("Time1") ?? "";
Time2 = player.GetVar("Time2") ?? "";
Time3 = player.GetVar("Time3") ?? "";
- HunterBlake7 months agoCommunity Member
What does this part
?? ""
do?
- Nedim7 months agoCommunity Member
I'm pretty sure you were initially getting this error during testing. At least, that's what I saw in my console when I first tested your project.
This error shows the sequence of function calls leading to the issue. The setText() function in PDFTextField.js fails because it expects a string but receives null. This suggests that the Storyline variable may not have been initialized yet, causing player.GetVar() to return null when the script tries to retrieve it.
To prevent this, the ?? "" (Nullish Coalescing Operator) ensures that if player.GetVar() returns null, it defaults to an empty string ("") instead of breaking the setText() function. Once the actual Storyline variable values become available, they will automatically replace the empty string.
In short, this approach prevents errors when calling setText(), ensuring that the code remains functional even if a Storyline variable hasn’t been initialized yet.
- HunterBlake7 months agoCommunity Member
Thank you. It worked! You rock!
Related Content
- 7 months ago
- 2 months ago