Storage.setItem()

Overview

Stores a value into the application's internal persistent store. The values are shared between all profiles and sessions on the device and will persist until the application is uninstalled or the application's data is cleared. This is similar to the persistent variables in the Terminal Emulation Client.

Because writing new values to storage will slow your application, they should only be used when necessary. If you want to use a stored item that will change values frequently, write your script with a regular variable that only changes the value in storage before the script completes.

Added in version 1.2.109

Use Cases

Your script needs to maintain state between sessions.

Format

Storage.setItem(keyName, item);

Parameter Description Type Required Notes
keyName A string key that is used to retrieve the stored value in the future. String Required
item The item to store. The item can be of any type that can be stored using JSON. String, Number, Boolean, Array, Object Required The value cannot be undefined or null.

Example 1

Copy
/* Play a sound file the very first time this code is processed.
 */
 
if(!Storage.getItem('doneThisOnce')) {
  Device.beepPlayFile('tada.wav');
  Storage.setItem('doneThisOnce', true);
}