App Preferences
Overview
Available since Glue42 Enterprise 3.12
The App Preferences API is accessible through the glue.prefs
object.
See the JavaScript App Preferences example on GitHub.
Get
To retrieve the stored app preferences for the current app, use the get()
method:
const prefs = await glue.prefs.get();
This method resolves with an AppPreferences
object with the following properties:
Property | Type | Description |
---|---|---|
app |
string |
The name of the app with which are associated the stored preferences. |
data |
object |
The stored app preferences. |
lastUpdate |
Date |
Timestamp of the last update of the app preferences. |
To retrieve the stored app preferences for a specific app, pass an app name to the get()
method:
const appName = "clientlist";
const prefs = await glue.prefs.get(appName));
To retrieve the stored app preferences for all apps of the current user, use the getAll()
method:
// Resolves with a collection of `AppPreferences` objects.
const prefs = await glue.prefs.getAll();
Set
To set the preferences for the current app, use the set()
method:
const prefs = { fontSize: 18 };
await glue.prefs.set(prefs);
The set()
method replaces entirely the stored app preferences. All existing properties of the AppPreferences
object associated with the app will be removed and replaced with the ones of the argument provided to the set()
method.
To set the preferences for a specific app, pass an options object containing the app name as a second argument to the set()
method:
const prefs = { fontSize: 18 };
const options = { app: "clientlist" };
await glue.prefs.set(prefs, options);
Update
To update the preferences for the current app, use the udpate()
method:
const prefs = { fontSize: 18 };
await glue.prefs.update(prefs);
The update()
method modifies only the properties provided in the update object. All other existing properties of the AppPreferences
object associated with the app will remain intact.
To update the preferences for a specific app, pass an options object containing the app name as a second argument to the update()
method:
const prefs = { fontSize: 18 };
const options = { app: "clientlist" };
await glue.prefs.update(prefs, options);
Clear
To remove the stored app preferences for the current app, use the clear()
method:
await glue.prefs.clear();
To remove the stored app preferences for a specific app, pass an app name to the clear()
method:
const appName = "clientlist";
await glue.prefs.clear(appName);
To remove the stored app preferences for all apps of the current user, use the clearAll()
method:
await glue.prefs.clearAll();
Reference
For a complete list of the available App Preferences API methods and properties, see the App Preferences API Reference Documentation.