Company logo
November 15, 2020

Specify arguments in programmatically-defined commands

Richard Freling's avatar
Vinay Ayyala's avatar

We now support arguments for programmatically-defined commands. See more details here.

For those that learn better by example, check out this code!

window.CommandBar.addContext('cereals', cereals);
window.CommandBar.addCallback('Set favorite cereal', setFavoriteCereal);
  text: 'Set favorite cereal', // command text the user sees
  name: 'set_favorite_cereal',
  template: {
    type: 'callback',
    value: 'Set favorite cereal' // using the callback set in the second line
  arguments: {'cereal': 
      type: 'context',
      value: 'cereals', // using the context set in the first line
      order_key: 0,
      label: 'Select one',
      label_field: 'label',
  category: 924,
  icon: '⭐',

Here's what we get in the Bar (a callback command with a list of cereals as the argument):

How can I turn this on? 🛠

If you have a programmatic command where you want to use this, just set the "arguments" property.