addRecordAction(recordKey, action, isDefault?, shownInDefaultList?)
Registers an action for a record.
Example
// Add record for this action to be available
window.CommandBar.addRecords('users', [{'label': 'Jack', 'id': 1}, {'label': 'Jill', 'id': 2}]);
// Link
window.CommandBar.addRecordAction('users', {
text: 'Open Profile',
name: 'open_profile',
template: {
type: 'link',
value: '/profile/{{record.id}}',
operation: 'self' // how should the page open
},
});
// Callback command
window.CommandBar.addRecordAction('users', {
text: 'Message',
name: 'message',
template: {
type: 'callback',
value: "messageUser",
},
});
// Wait for addRecordAction to complete
await window.CommandBar.addRecordAction(...);
Method parameters
recordKey Required
string
The record key that this action will be associated with.
action Required
object
The action schema. This is the same as a command.
Property | Type | Description |
---|---|---|
name | string | A unique identifier for the action. The name must be globally unique if two actions or commands have the same name, they can overwrite each other. |
text | string | The label shown to the user in Spotlight |
template | object | The schema defining the action (what happens when executed) |
heading | string | The string shown above text in Spotlight |
explanation | string | The subtitle string shown under text in Spotlight |
icon | string | Icon to show alongside this action. Can be a URL (absolute or relative) or emoji character. |
__image | string | Image to show when the record action is displayed in a grid. |
celebrate | string | If true , shows confetti when a user executes the action. |
isDefault | boolean | Whether this record action will be the default action for the selected record. Only applicable if multiple actions are being added for a given recordKey . If this value isn't provided, the last record action added for a recordKey will be treated as the default. |
shownInDefaultList | boolean | Whether this record action will be also treated as a command and shown in the default list. |
template
object
Property | Type | Description |
---|---|---|
type | "link" | "callback" | The action type |
value | string | For link commands: The URL to open. For callback commands: The callbackKey . |