Passing Values into StoryLine

May 02, 2013

I would like to pass a userName and userID into StoryLine from the story.html page.

I tried created a javaScript function in an external js file and loading it into the story.html page. and then calling the function from a trigger inside the story file. I tried using the GetPlayer() and player.SetVar() methods but I couldn't get the variable to update inside the story file.

Any help would be appreciated.

Thanks David

18 Replies
Steve Flowers

Give this a shot in a javascript trigger:

function getQueryVal(variable) {

    var query = window.location.search.substring(1);

    var vars = query.split('&');

    for (var i = 0; i

        var pair = vars[i].split('=');

        if (decodeURIComponent(pair[0]) == variable) {

            return decodeURIComponent(pair[1]);

        }

    }

}

var player=GetPlayer();

//storyline variables userName and userID must exist for this to work

player.SetVar("userName", getQueryVal("userName"));

player.SetVar("userID",getQueryVal("userID"));

//using this setup, the URL construction below should work

//http://yourURL/story.html?userName=Joe Johnson&userID=1234

Mark Cairns

Hello,

I'm having trouble getting this to work. Maybe I'm misunderstanding.

I have two variables added to my Storyline: userID and userName.

I have the following JavaScript executing when the timeline starts:

function getQueryVal(variable) {

    var query = window.location.search.substring(1);

    var vars = query.split('&');

    for (var i = 0; i

        var pair = vars[i].split('=');

        if (decodeURIComponent(pair[0]) == variable) {

            return decodeURIComponent(pair[1]);

        }

    }

}

var player=GetPlayer();

//storyline variables userName and userID must exist for this to work

player.SetVar("userName", getQueryVal("userName"));

player.SetVar("userID",getQueryVal("userID"));

Also, I have two variable references on the first slide to display: %userName% and %userID% 

Finally, I have uploaded the published files to http://capabilityx.ca/dev/story.html

However, When I go to the URL - http://capabilityx.ca/dev/story.html?userName=Joe Johnson&userID=1234

I don't see Joe Johnson and 1234 in my variable references on the first slide.

Any help would be appreciated. I've uploaded my .story file.

Thanks,

Mark

Steve Flowers

Hah. Pesky less than sign. The forum swept away part of the code. That's making your function error. Let's see if it works this time:

function getQueryVal(variable) {

    var query = window.location.search.substring(1);

    var vars = query.split('&');

    for (var i = 0; i

        var pair = vars[i].split('=');

        if (decodeURIComponent(pair[0]) == variable) {

            return decodeURIComponent(pair[1]);

        }

    }

}

var player=GetPlayer();

//storyline variables userName and userID must exist for this to work

player.SetVar("userName", getQueryVal("userName"));

player.SetVar("userID",getQueryVal("userID"));

BJ Campbell

*** JAVASCRIPT AND STORYLINE ***

I've been working on a test module that calls values in a javascript trigger, but it is not working.  Can anyone review this?  Any suggestions?

JavaScript JS(1) does not seem to be working.  JS(2) does seem to be working.

=============================

JS(1) triggered when timeline starts:

var player = GetPlayer();
player.SetVar("UniqueID", "#!#UNIQUEID#!#");
player.SetVar("ResponseURL", "#!#RESPONSEURL#!#");

=============================

JS(2) triggered when pass quiz (status=passed)

var player = GetPlayer();
 var status = player.GetVar("Status");
 var uniqueid = player.GetVar("UniqueID");
 var responseurl = player.GetVar("ResponseURL");

 // ajax start
 var xhr;
 if (window.XMLHttpRequest) xhr = new XMLHttpRequest(); // all browsers
 else xhr = new ActiveXObject("Microsoft.XMLHTTP"); // for IE

var url = responseurl + '?status=' + status + '&uniqueid=' + uniqueid;
alert("opening: " + url);
 xhr.open('GET', url, false);
 xhr.onreadystatechange = function () {
 //4: request finished and response is ready
 // 200: “OK” else 404: “Page not found”
if (xhr.readyState===4 && xhr.status===200) {
 // you can uncomment the following line to test if the vars are passed
 // a pop-up will be displayed
//alert(xhr.responseText);
 }
 }
 xhr.send();
 // ajax stop
 return false;

 

Sumit Ghosh

Hi Steve,

I am trying this with an objective to make the player switch to a particular slide based on two variables passed through the URL. I do not have access to any web server. So, I have to test it locally. But, so far, I am unable to do it. Can you please suggest a way I can test it locally? Also, I would prefer working with a single variable instead of 2. Can you please modify the code accordingly. I have very little idea of Javascript.

Thanks in advance.

Sumit

Michael Bauer

Hi there, time for a Java for Dummies question as I have never used it before. I tried to follow it from here, but I'm a little unsure (and of course it didn't work for me!). I want to show the User Name in my Storyline course from the Storyline, I have set up the following:

Text on screen: %userName%

Trigger: Execute Java Script when timeline starts, and in the java script I have the following:

function getQueryVal(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
}
var player=GetPlayer();
player.SetVar("userName", getQueryVal("userName"));

I have zero idea on what the above means, but perhaps someone can help me out? I have attached my Storyline 360 file also, and am using SuccessFactors LMS.

This discussion is closed. You can start a new discussion or contact Articulate Support.