Skip to main content
Inspiring
November 8, 2017
Answered

CP9 getVariableValue not pulling through value.

  • November 8, 2017
  • 1 reply
  • 407 views

Version : CP9 9.0.2.437

OS        : Windows 7

Output  : HTML5 only

Type     : Non responsive

Hello,

I hate asking questions with a whole load of code, so apologies in advance, but it is just one line that is the problem.

I have placed some java in a HTML page.

I have used a Web Object to display the HTML page on a Captivate Slide, and display on the slide.

I am trying to get the java in the HTML page to use a value from a Captivate User variable using the code: var tmpROLE = window.cpAPIInterface.getVariableValue("varRole");

Unfortunately the code does not work.

The Captivate User variable "varRole" does exist as I'm using it throughout the project.

If I change the line to 'hard code' a dummy test value, the code works: var tmpROLE = "DOCTOR";

Therefore I can only think that there is something wrong with the code window.cpAPIInterface.getVariableValue("varRole");

Can anyone see anything obviously wrong?

Thank you

Peter

This is the code in question, please don't be too cruel about it, I'm not a programmer.

==== THIS DOES NOT WORK =====================================================================

<script>

function myFunctionURL(tmpCOURSE,tmpLINKTEXT) {

var tmpNADEX = window.localStorage.getItem("varLocalNADEX");

var tmpROLE = window.cpAPIInterface.getVariableValue("varRole");

var tmpURL = "start_training.php?" + tmpCOURSE + "&NADEX=" + tmpNADEX;

document.write('<a href="' + tmpURL + '"' + ' target="_top">' + tmpLINKTEXT + '</a>');

}</script>

<body>

<table>

<tr>

<td class="cell_ref"><script>myFunctionURL("COURSE=104_meds_verify","Verify medications for the DAL")</script></td>

</tr>

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

=== THIS WORKS ======================================================================

<script>

function myFunctionURL(tmpCOURSE,tmpLINKTEXT) {

var tmpNADEX = window.localStorage.getItem("varLocalNADEX");

var tmpROLE = "DOCTOR";

var tmpURL = "start_training.php?" + tmpCOURSE + "&NADEX=" + tmpNADEX;

document.write('<a href="' + tmpURL + '"' + ' target="_top">' + tmpLINKTEXT + '</a>');

}</script>

<body>

<table>

<tr>

<td class="cell_ref"><script>myFunctionURL("COURSE=104_meds_verify","Verify medications for the DAL")</script></td>

</tr>

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

    This topic has been closed for replies.
    Correct answer Jim Leichliter

    Try putting "parent" in front since you are using an web object to display the web page.  the web object becomes a child of the parent Cp course:

    parent.window.cpAPIInterface.getVariableValue("varRole");

    1 reply

    Jim LeichliterCorrect answer
    Legend
    November 8, 2017

    Try putting "parent" in front since you are using an web object to display the web page.  the web object becomes a child of the parent Cp course:

    parent.window.cpAPIInterface.getVariableValue("varRole");

    Inspiring
    November 8, 2017

    Jim,

    100% perfect!

    Thank you.

    Peter