---
title: Dynamic data
slug: dynamic-data
description: Learn how to send xAPI statements using string, boolean, and number variables with the HypeXAPI export script. This tutorial covers setting and changing variable values, using the "Run Expression" function for mathematical operations on number variables, 
docTags: 
createdAt: 2022-04-12T08:34:25.000Z
---

This tutorial sends 4 independant xAPI statements using 2 syntax structures, by using a string variable.

::embed[]{url="https://youtu.be/IGIu-N74-MM"}

If you know Hype and know your way around JavaScript, you have seen a few ways of how to dynamically update data for the statements by now. But for the other people like me, I need to show you a few methods of how to dynamically update data.&#x20;

Variables are stored in `hypeCustomData`. I try to identify the variables that I will use upfront and declare default values for the variables in the HypeXAPI() document. Something like this:

```javascript
    //set dynamic data
    
   		hypeDocument.customData.myResponseVariable = '';
   		hypeDocument.customData.raw = 0;
   		hypeDocument.customData.scaled = 0;
   		hypeDocument.customData.success = false;
   		hypeDocument.customData.videoName = 'rocket';
   		hypeDocument.customData.kCheck1 = "quiz_1";
```

Once they are declared here, you can adjust them in the GUI.

To add a string variable somewhere in your dictionary, add it in place like this:

```javascript
		'myresult1': {
		
				"response": '${myResponseVariable}', //string variable placeholder

			},
```

To create placeholders for the boolean and number variables:

```javascript
		'myresult2': {

				"score": {
					"raw": function() {return hypeDocument.customData.raw},//number variable
					"scaled": function() {return hypeDocument.customData.scaled},//number variable
				},
			
				"completion": true,	
				"success": function() {return hypeDocument.customData.success},	//boolean variable
			},
		
		
    });
```

***

### Set these variables in the GUI.

When you have loaded the HypeXAPI export script, you have the ability to set/change the variable values from the actions panel. Changing the values of a string, boolean or a number variable happens the exact same way. For example:

::Image[]{src="https://api.archbee.com/api/optimize/g-TEMWDtkenjdIIxVVk08/tjmg7raeC0jTwTpZPppxE_booleanvariable.png" size="28" width="522" height="222" caption="boolean variable" position="center" showCaption="true"}

::Image[]{src="https://api.archbee.com/api/optimize/g-TEMWDtkenjdIIxVVk08/hrKCbXfiZVBRjNlB7UrGp_numbervariable.png" size="28" width="508" height="220" caption="number variable" position="center" showCaption="true"}

::Image[]{src="https://api.archbee.com/api/optimize/g-TEMWDtkenjdIIxVVk08/oIHEYIT9Hj9UDES1MIGlC_stringvariable.png" size="28" width="520" height="226" caption="string variable" position="center" showCaption="true"}

### Run expression...

The `Run Expression` choice in the actions HypeXAPI export script is a special one. Especially for a non-coder like me. If you have declared a value for a variable in` hypeDocument.customData`, you can do things with `Run Expression`.

For example, you can change a number variable with some maths:&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/g-TEMWDtkenjdIIxVVk08/e9QFFukNPrAJBd2lTXd-N_runexpression1.png" size="28" width="528" height="172" position="center" showCaption="false"}

Here we take the variable 'raw' that was set in hypeCustomData and we are adding 5 to its number value.

::Image[]{src="https://api.archbee.com/api/optimize/g-TEMWDtkenjdIIxVVk08/r05Ofm_UN_rbCo5GVcqap_runexpression2.png" size="28" width="524" height="172" position="center" showCaption="false"}

Now we take the same vaiable and subtracted the number value 2 from it.

::Image[]{src="https://api.archbee.com/api/optimize/g-TEMWDtkenjdIIxVVk08/2s4Nb_bBe6xJHN_vblS_U_runexpression3.png" size="28" width="540" height="192" position="center" showCaption="false"}

Now we multiplied the same 'raw' variable and multiplied it by 2.

You can also run some basic JavaScript in `Run Expression` as well.

::Image[]{src="https://api.archbee.com/api/optimize/g-TEMWDtkenjdIIxVVk08/5QZ4wJIVq8nzr2JBgItPP_runepressionconsole.png" size="28" width="520" height="138" position="center" showCaption="false"}

Something else to consider when using `Run Expression`, is to pass basic Hype specific JavaScript like this into it:

```javascript
myResponseVariable = document.getElementById('myText').value
```

Here we take the innerHTML value of 'myText' and pass it into the variable `myResponseVariable`.

The rest is up to you. Have fun with the dynamic data options with the Hype Export script.

## Run expression tutorial with timer

::embed[]{url="https://youtu.be/ZXo1d_ng0zc"}

### ISO time conversion function

```javascript
 	 var seconds = hypeDocument.customData.slideTimer;
		  if (seconds > 60) {
  			  if (seconds > 3600) {
					const hours = Math.floor(seconds / 3600);
					const minutes = Math.floor((seconds % 3600) / 60);
					seconds = (seconds % 3600) % 60;
					
     	 hypeDocument.customData.slideDuration =  `PT${hours}H${minutes}M${seconds}S`;
     	 
					} else {
						const minutes = Math.floor(seconds / 60);
						seconds %= 60;
					
      	hypeDocument.customData.slideDuration =  `PT${minutes}M${seconds}S`;
    		}
  
  		} else {
  		
 		hypeDocument.customData.slideDuration =  `PT${seconds}S`;
  }
```

## Expanding on the result object

The following tutorial shows how to use and update Boolean and number variables, using the Result object as a use-case.

::embed[]{url="https://youtu.be/y3MFDKDL3M8"}
