Completing a URL with a variable
Mar 10, 2014
Hello,
I'm working on a project in which I would like users to type in their employee ID to access a personalized report via URL. Let's say my employee ID is 1234 and my URL is something like www.company.com/report/userID=1234.pdf.
I would like the user to enter their employee ID at the beginning of the course, then use that variable to fill in the "1234" portion of the URL above.
I'm a javascript novice, but I I'm pretty sure it can be done. It seems like it is possible using the player.GetVar method mentioned in the JavaScript Best Practices. Any ideas?
Thanks,
Matt
7 Replies
I just visited with a colleague who answered my question.
Originally, I was using a text variable named "UserID" in Storyline to capture the employee ID and my code looked like this:
var player = GetPlayer ();
window.open("http://www.company.com/report/user=" + player.GetVar (UserID)+ ".pdf");
This wasn't working because JavaScript can only insert JavaScript variables into the window.open line. So I needed to use the Storyline variable to define the JavaScript variable (which I named "number"), which looks like this:
var player = GetPlayer();
var number = player.GetVar ("UserID");
As you may have noticed, I also forgot to include the quotation marks around my Storyline variable in the original code. Now that I have created a JavaScript variable, I can insert it in the window.open line. The full code looks like this:
var player = GetPlayer();
var number = player.GetVar ("UserID");
window.open("http://www.company.com/report/userID=" + number + ".pdf");
This worked for me. I hope this helps someone else.
Thanks Matt for coming back to update the thread with the solution you found. Also, welcome to the Heroes community!
Hello,
I came across this post, but the JS code is not returning the UserID only a blank. I need to be able to submit quiz results to a separate app. I tried getting UserID, Email, FirstName, LastName, but none of them seem to actually return anything.
Any advise?
Thanks!
UserID is the name of a variable that Matt had created and populated in Storyline. The GetVar gets that variable from Storyline.
Thanks Walt! That makes sense then.
I am using Articulate Online and need to send quiz results to an app outside AO. I was hoping to pull either the email address or the user ID once the user arrives at the results slide to be able to map quiz results to the correct user in the app.
Do you know if the user information can be retrieved from the course module?
I'm not sure about AO, but they do have a forum dedicated to it. At the top of the page, check out Discuss, and products.
Thanks Walt. I posted under AO.
This discussion is closed. You can start a new discussion or contact Articulate Support.