Transfer user input data from one captivate file to another

Explorer ,
Dec 17, 2014 Dec 17, 2014

Copy link to clipboard

Copied

Greetings.

Using one Captivate 8  file to password protect access to another Captivate 8 file.

The user logs in with their user name, which is assigned to a variable $$username$$.

Can I somehow transfer this user name to another Captivate file which is opened by the first file?

Hope the question is clear.

Thanks so much.

Daniel.

TOPICS
Advanced

Views

2.2K

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 17, 2014 Dec 17, 2014

Copy link to clipboard

Copied

You can do this using URL parameters or LocalStorage. 

Using the browser's localStorage JavaScript object:

You can set/store an item to storage like this:

window.localStorage.setItem('StudentName', window.cpAPIInterface.getVariableValue("StudentName"));

In the other course, you can retrieve the value like this:

window.cpAPIInterface.setVariableValue("StudentName", window.localStorage.getItem('StudentName'));

This assumes you have a Captivate user variable called "StudentName" in both Captivate projects.

Jim Leichliter

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 17, 2014 Dec 17, 2014

Copy link to clipboard

Copied

I left out that the first bit of code would probably be executed on a text entry box's submit button.... or any button.

The second bit of code could go on slide entry of the first slide of the other captivate project.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 17, 2014 Dec 17, 2014

Copy link to clipboard

Copied

Hello again.

Oh, so you append it to the URL in the outgoing Captivate file?

So if the url I use is, say,  http://www.website.com/quiz.html,

I can make it: http://www.website.com/quiz.html/window.localStorage.setItem('StudentName', window.cpAPIInterface.getVariableValue("StudentName"));

?

And to retrieve the value, where would I add the second string?

Thanks so much, Jim!

Daniel.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 17, 2014 Dec 17, 2014

Copy link to clipboard

Copied

Hi Daniel,

localStorage is done through JavaScript and needs to be done in Captivate using an "Execute JavaScript" action.  URL parameters is a different way to transfer data, but localStorage is going to be much easier to use so I provided the example.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2014 Dec 19, 2014

Copy link to clipboard

Copied

Hi Jim.

I've been struggling with this for a few days, so perhaps you can advise,

please.

Leaving the first page where the User logged in, the UserName was snagged

by the javascript

window.localStorage.setItem('UserName', window.cpAPIInterface.

getVariableValue("UserName"));

At the receiving end, I have to run the javascript

window.cpAPIInterface.setVariableValue("UserName",

window.localStorage.getItem('UserName'));

to pick up the UserName. I put this on the "On Enter" of the page.

The problem is that I also have to have a conditional statement...If

UserName = joeschool (for example) then assign the appropriate google

script for the widget.

How can I execute a javascript command in an advanced action AND the

conditional script assignment in a conditional advanced function? It

seem I can only do either a standard action OR a conditional action?

thanks so much.

Daniel Berlin.

On Wed, Dec 17, 2014 at 9:00 AM, Jim Leichliter <forums_noreply@adobe.com>

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 19, 2014 Dec 19, 2014

Copy link to clipboard

Copied

Hi Daniel,

An advanced action can have multiple condition statements by using the buttons highlighted in red below.  Each button can hold a condition statement.  To always run a conditional statement, you can set 1 = 1 which will always evaluate to true, so the condition (the javascript in this case) will always run.

multipleConditions.jpg

Best,

Jim Leichliter

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 27, 2015 Jan 27, 2015

Copy link to clipboard

Copied


Hello,

This is my first post in any Adobe forum, and hopefully someone will be able to help.

I'm using Captivate 8, IE 8, Win 7, and have just started to play with Javascript.

The task I need to do is exactly as laid out in Jims post...store some data for use by the next project.

I have created a project with 1 slide.

I have created a variable called StudentName with a Default value of "peter" (without quotes)

The slide has an On Enter action to Execute Javascript

I have put in the following script:

// Show an alert to prove the code is running.
alert("start");

//Show an alert to prove my variable has the Default data in it.
alert(window.cpAPIInterface.getVariableValue("StudentName"));

//Store the data from my variable for use by the next project.
window.localStorage.setItem('StudentName', window.cpAPIInterface.getVariableValue("StudentName"));

//Show an alert to prove the code got to here.
alert("end");

I have used F12 to run it.

The alert for "start" works

The alert for my StudentName variable works.

BUT, the alert for "end" does not show.

I guess that the code for storage has caused some sort of error and the script has stopped.

I commented out the line of code

//window.localStorage.setItem('StudentName', window.cpAPIInterface.getVariableValue("StudentName"));

and all three alert boxes are shown.

I have published the swf file and placed in on our internal server, but still no luck.

I have not attempted a script to retrieve the varaible yet, as Im not certain it is being stored.

My question is: Please can someone tell me what has gone wrong with what should be a simple bit of script?

Thank you.

Peter

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 27, 2015 Jan 27, 2015

Copy link to clipboard

Copied

petern33480613:

Hi Peter and welcome to the forums.  Here's a few things to check:

  • Sometimes forums and text editors will automatically convert straight quotes into slanted quotes which becomes and issue when you copy and paste.  The JavaScript engine cannot parse slanted quotes.  Go back over the quotes and type them in by hand.  Be consistent using either single or double on a single line (and I see from my previous example, I should follow my own advice)
  • Use Google Chrome for testing and you can also wrap your code in a try catch block to output any errors to the console:

try{

  window.console.log('BEGIN');

  var sName = window.cpAPIInterface.getVariableValue("StudentName");

  window.console.log('Set Student Name In Local Storage');

  window.localStorage.setItem("StudentName", sName);

  window.console.log('END');

} catch(err){

  window.console.log(err);

}

You can hit CTRL+ALT+J to open Chrome's JavaScript console.  If you are on a Mac, that would be CMD+ALT+J.  You should see the console statements being output.  This is better than using alert statements since console.log doesn't block the javascript execution.  You'll also catch your errors in the console.

  • I've also had issues in Cp 8 where JavaScript on entry of the first slide just doesn't fire.  In some projects it's fine, in others, it just doesn't execute.  I have not figured out a rhyme or reason for this.  The only workaround is to put it on slide exit... or entry of the following slide.

Try the above ideas and if they don't work, share your project and I can have a look.

Best,

Jim Leichliter

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 28, 2015 Jan 28, 2015

Copy link to clipboard

Copied


Jim,

All is good.

Your explanation was clear and your code worked, thank you.

I had to play around an awful lot... and got help from a passing techie, but it works

One thing I discovered is that our Antivirus (McAfee) hinders the usage of any folder with the word 'temp' in it.

As Captivate uses a temp folder when the F12 key is pressed, I was running into problems there, even though I did not know it until the tech people told me.

(When I enquired whether this 'temp' setting could be changed in the anitvirus the answer was a very loud "No !")

So the only way I could test it was to run it from the proper server each time.

Once again, thank you so much.

Peter

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 28, 2015 Jan 28, 2015

Copy link to clipboard

Copied

@Peter:  Nice work!  Glad you stuck it through to see a solution!

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 31, 2016 May 31, 2016

Copy link to clipboard

Copied

I tried the solution Jim and it worked perfectly. Is there a way of transferring data so it's not stored locally on the machine. For example in shared device circumstances.

How does the URL parameters work?

Ideally it would be great to store the data in the browser, then when it's closed the data would be wiped.

I'm not sure if that's possible?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 31, 2016 May 31, 2016

Copy link to clipboard

Copied

localStorage can be cleared when the browser is closed. You use sessionStorage instead of localStorage.

Both localStorage and sessionStorage are stored in the browser. In the way that each browser stores it in it's own location and the setting are done in the browser.

URL parameters append data to the URL, but the page that sends the parameters needs to open the second page.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

Thanks TLCdigilabel

The reason I was asking is I thought local storage stored data on the device itself?

For example we have set up a simple score variable that loads/saves across different modules in the LMS. However if a different user loads a module on the same device and loads the score it will just pull in the data from the last person's save.

I figured ways around it. But wanted to see if there was another storage command that could be used that would be wiped when the browser is closed, just for more flexibility when designing.

I'll give sessionStorage a test out and see how that works.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

Local Storage DOES store the data on the device.  But if your users are all using the same user login account then that would explain why you're seeing this behaviour.  Is that the case?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

Yeah I was logged into windows... but testing using different people's log ins on the LMS.

So if someone else logged into the machine it wouldn't happen? So it remembers it based on the log in to the machine?

Thanks

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

It's related to the user profile on the machine, not the LMS.  So if you were using the same profile on the PC, then the browser is storing all the local storage data in the same place.

Log into the PC as someone else and try it again.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 01, 2016 Jun 01, 2016

Copy link to clipboard

Copied

You can a prepend different information to the storage to allow different users on the same computer. Below is an example using the course name derived from the Preferences/Project/Information/Project Name: field (HTML5) and the cpQuizInfoStudentName variable.

var sID = window.cpAPIInterface.getVariableValue( 'cpQuizInfoStudentID' );

var pID = cp.model.data.project.pN;

var lessonStorage = pID + '.' + sID ;  

if ( typeof( Storage ) !== 'undefined' && window.location.protocol.indexOf( 'http' ) != -1 )

localStorage.setItem( lessonStorage, JSON.stringify( yourDataVariable ) );

}

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 28, 2016 Jul 28, 2016

Copy link to clipboard

Copied

I thought I'd continue in this thread as it's about the same subject rather than start a new one.

I've been testing the local storage and have a cptx project that saves and loads three variables. In the javascript window I've literally stacked the code on top of each other. For each variable like in the below:

window.localStorage.setItem('StudentName1', window.cpAPIInterface.getVariableValue("StudentName1"));

window.localStorage.setItem('StudentName2', window.cpAPIInterface.getVariableValue("StudentName2"));

window.localStorage.setItem('StudentName3', window.cpAPIInterface.getVariableValue("StudentName3"));

I tested it in Captivate by previewing in the browser (in Safari on a Mac) and it works as long as I come back to the project file and preview again in the same day.

However, I thought it would have worked still no matter how long I left it. Admittedly, I've yet to publish the swf so I've done that and tested it in Safari and Chrome and will leave it a couple of days before accessing it again and 'loading' the variables.

However, the good news is that our users don't use Macs they're all on windows based machines... I fired up the test file I create a couple of months go in Internet Explorer (The default browser our users have). This only has a single variable that loads/saves and it had been hosted on the LMS and it worked perfectly loading up the score I had saved a couple of months earlier.

I'm also going to test to the published swf with 3 variables on the windows machine to see if it works on there.

So I guess what I'm asking is whether

a) previewing in captivate should make the local storage behave any differently?

b) Whether it's an issue with Safari or specifically using a mac?

c) Whether it's an issue with the coding, although this seems the least likely as it does save/load the variables if I access it multiple times in the same day/while the machine is on. I have gone back into Safari and checked all my history etc is still there as I know the local storage gets wiped when clearing the browser cache.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 28, 2016 Jul 28, 2016

Copy link to clipboard

Copied

Answers to your questions.

a: Yes, previewing in Captivate would certainly effect the way that local storage would work. Think of local storage information as being put into little boxes, and none of these boxes can touch. Every browser has its own set of boxes (local storage can't be transferred between browsers) and every website has its own box (google.com can't share local storage data with adobe.com). When you preview in Captivate, you are most looking at a local host server generated by Captivate. That would have it's own little box. Captivate at certain points (it's hard to say when as we're not part of the development team) resets the local host server. At which point the local storage data would be lost, or at least no longer accessible.

So if you want to test local storage with any kind of consistency, you need to be publishing your Captivate content and viewing it on your own local host server.

b: Local Storage is quite a well established standard in browsers. I have never heard any trouble with MACs or Safari. Certain minor versions of Internet Explorer however have bugs with it. Make sure your version is up to date.

c: The time delay deletion you're experiencing has nothing to do with the code. Javascript can't set an expiry time for a local storage variable. It has to be server or browser related.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 29, 2016 Jul 29, 2016

Copy link to clipboard

Copied

Thanks for your answers Widget King I really appreciate it.

So I've gone back to my working file which only has the one variable to save/load. To further test it.

As I mentioned in my last post, in the LMS it works fine, when uploaded as a SCORM package.

I did some further testing and noticed that it won't work if it's a SWF by itself, no matter where it's hosted. I also published the SWF file zipped up and hosted it on a company team site, as opposed to the LMS, and again it wouldn't work as in order to access the SWF file I had to unzip it.

So I've come to the conclusion that it's to do with where it's being hosted and in what format, which seems strange as I thought that wouldn't have any impact on the Javascript as it's still being run in the browser?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 29, 2016 Jul 29, 2016

Copy link to clipboard

Copied

The functionality relies on JavaScript.  If you only run the SWF alone you don't get the benefit of the JS code that you would need to achieve your goals here.  Captivate typically publishes an SWF with an HTM file as well as a JS file and CSS (for formatting).  So unless you choose to launch the SWF file via the HTM as intended by Captivate's designers, you will not get all the functionality you could have.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

Hi, unless I'm missing something, this can only work if the same user is using the same machine to access the file. I was thinking of setting up something like this:

File 1 asks whether they're Team 1 or Team 2 - based on their response it opens File 2.

File 2 is for Team 1 who has data for their game (on Team 1's one computer as it's being completed through Breakout Rooms in a VILT setting)

File 3 if for Team 2 who has data for their game (on Team 2's one computer as it's being completed through Breakout Rooms in a VILT setting)

File 4 is for displaying the results of the game while it is still being played. It would contain the variable passed from File 2 and File 3 and it would be opened by the trainer as a leaderboard.

Is this doable or is this something that has to be done through the LMS?

Thanks!

Robert Hannan

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines