UI Builder - how to check for existing, matching record before save, and give user option to cancel?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 02:00 PM
I've been following the video on constructing a simple app and inserting records. My button does an insert, or an update, like so:
const macAddress = api.state.deviceMacAddress || "";
const serialNumber = api.state.deviceSerialNumber || "";
const model = api.state.deviceModel || "";
...
var query = `u_mac_address=${macAddress}`;
query += `^u_model=${model}`;
query += `^u_serial_number=${serialNumber}`;
...
var payload = {
"table": api.context.props.table,
"recordId":api.context.props.sysId,
"templateFields":query,
"useSetDisplayValue":false
};
api.data.update_device.execute(payload);
And that works fine. But I'd like to check (through a Look Up Records resource) if there is an existing record matching these values, and give the user the option to skip the insert (or update), such as by displaying a modal that gives the user the option to cancel. But I do not see how to launch a modal from here, or take any action that informs the user or gives them an option to cancel.
I feel like I need to emit an event from the save button, and assign a handler that checks the data resource, and if it sees an existing record, it emits Event A, otherwise event B, and the handler for A pops up a modal, while the handler for B proceeds with the insert/update. Is there a way to do this?
- Labels:
-
Now Experience UI Framework

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 07:11 PM
I think what I would do here is a series of things chained together:
- On the button press, call/refresh the lookup data resource (it'll execute async).
- The data resource should fire an event when it successfully completes, and you can run a client script then that examines the payload and either does the update or opens the modal.
- If the user doesn't want to cancel, call the client script that executes your update device data resource.