Skip to content

UX Data Broker Transform Create/Update User Preference #1574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* This data broker creates or updates a user preference of the given name with the given value
* @param {{name: string, value?: string}} inputs inputs from the properties field above
*/
function transform({ name, value }) {
const lib = "Data Broker";
const func = "Create/Update User Preference";
try {
if (!name) throw new Error("Missing required param 'name'");


gs.getUser().savePreference(name, value);
} catch (e) {
gs.error(`${lib} ${func} - ${e}`);
throw new Error(e);
}
}

/**
* Make sure to select that this data broker mutates data
* Input this in the properties field:
*
[
{
"name": "name",
"label": "Name",
"description": "The name of the user preference to create or update",
"readOnly": false,
"fieldType": "string",
"mandatory": true,
"defaultValue": ""
},
{
"name": "value",
"label": "Value",
"description": "The value to store in the user preference",
"readOnly": false,
"fieldType": "string",
"mandatory": false,
"defaultValue": ""
}
]
*/
29 changes: 29 additions & 0 deletions UX Data Broker Transform/create-update-user-preference/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Create/Update User Preference Data Broker

This repository provides a data broker for creating or updating user preferences in ServiceNow. The broker allows you to specify a preference name and value, storing or updating it in the user’s preferences.

## Features

- **Create or Update User Preferences**: Provides a simple interface for adding or modifying preferences by name and value.
- **Error Handling**: Logs errors if the preference name is missing or if an unexpected issue arises.

## Template Overview

```javascript
/**
* This data broker creates or updates a user preference of the given name with the given value
* @param {{name: string, value?: string}} inputs inputs from the properties field above
*/
function transform({ name, value }) {
const lib = "Data Broker";
const func = "Create Update User Preference";
try {
if (!name) throw new Error("Missing required param 'name'");

gs.getUser().savePreference(name, value);
} catch (e) {
gs.error(`${lib} ${func} - ${e}`);
throw new Error(e);
}
}
```
Loading