Reference Tool

Jan 27, 2016

I'm trying to find an efficient way to build a reference tool to accompany some training I'm developing.

The tool should allow users to input two pieces of data, I'll call them "Code 1" and "Code 2". Then those two pieces of data need to be compared to a predefined list of possible "Code 1" and "Code 2" combination that would either allow the process to continue, stop or take an alternative route.

There are 90 different combinations between Code 1 and Code 2 that could allow or deny the process to continue.

I'm looking for ideas on how to allow users to type in "Code 1" and "Code 2" and have an yes, no or other answer returned to them after it bumps the information against the list of possible answers.

12 Replies
Steve Gannon

Hi Aaron,

A little example is attached. Study the Javascript code in the Execute Javascript trigger. I used two arrays of sample values for Code 1 and Code 2. (I was unsure if the user's entries should be combined and compared against a single list of combined values. For now, I assumed each code will be compared against a unique list for that code.)

If a value is found in an array, Javascript will return the index (or the number of the item) where it is found. If the fifth item in the array matches the user's entry for that code, Javascript will return '4', since it begins counting from zero, not 1. If the value is not found, Javascript returns '-1'.

Hope this helps get you started! Let me know if you further guidance. 

Steve Gannon

Sometimes Javascript will get blocked when running directly from the local drive. Publish for the web and post the files to a web server. See if that helps.

If your IT department has blocked Javascript on your computer then, no, it won't work. You'll have to resort to numerous triggers to accomplish what you want in that case.

Steve Gannon

Here you go, Aaron.

The first line of Javascript was messed up (the actual line of code got pulled up to the end of the comment line above it) and two of your triggers needed to be tweaked (the conditions should be greater than or equal to zero, not just greater than 0; this is because index counting starts at 0, not 1).

I added a text box showing the value of the variables so you can monitor how they change. Just delete the box once everything is working to your liking.

Aaron Schweizer

OK Steve, I'm at my wits end. I've tried to troubleshooting the javascript but my limited knowledge is hindering me.  When I run the search it's only returning a result that no code is found. Even though I am searching options that exist within each array. I went back to your original example because I thought I might have changed something incorrectly while setting up my own variables. The Code1Found and Code2Found variable never update after I click search. What am I not getting? Did your original example work accurately?

//Initiate communication between Storyline and Javascript
var player = GetPlayer ();

//Get the two values the user entered in Storyline
var Code1=player.GetVar("Code1");
var Code2=player.GetVar("Code2");

//Set up two arrays to hold all possible values of each code
var array1 = ["LPK", "CIB"];
var array2 = ["01", "10"];

//Search the respective array for the respective value the user entered
var Code1Found = array1.indexof(Code1);
var Code2Found = array2.indexof(Code2);
//If Code1Found is >-1, Code1 was found; if -1, it was not found;
//If Code2Found is >-1, Code2 was found; if -1, it was not found;

//Send the results back to Storyline
player.setvar("Code1Found", Code1Found);
player.setvar("Code2Found", Code2Found);

Steve Gannon

It could be SharePoint, or it could be the browser security settings on your computer. Try this link: http://www.gantekmultimedia.com/sl_test/array2/story.html

Enter CIC in the first box and 15 in the second box and see what happens.

I tried it in Chrome and Firefox and it works properly. If you're using another browser (say, IE), you may need to speak with an IT associate to have him/her help you adjust the security settings.

 

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