Functions:runAction - bettyblocks/cli GitHub Wiki

We provided the helper function runAction so you can run an action (in this scenario often referred as a "sub action") in the foreground.

You will be able to use the resulting value of that sub action further on in your "main action".

Using the runAction helper

The runAction helper requires an object with the following keys:

  • id - the UUID of the (sub) action to be executed
  • input - an object containing input variable values for the (sub) action

As the helper function is an async function, you will have to await the function call. The return value of the function call is the result of the (sub) action.

For both the action ID and input variables we have provided the function option type Action and InputVariableMap respectively.

Example

We have created a runAction Block Store function of which you can find the implementation here:

const subAction = async ({ action: id, input }) => ({
  result: await runAction({ id, input }),
});

export default subAction;

This is the corresponding function.json (its blueprint):

{
  "description": "Execute an action",
  "label": "Sub Action",
  "category": "Misc",
  "icon": {
    "color": "Orange",
    "name": "LightingIcon"
  },
  "options": [
    {
      "meta": {
        "type": "Action",
        "validations": { "required": true }
      },
      "name": "action",
      "label": "Action",
      "info": "The (sub) action that needs to be executed"
    },
    {
      "meta": {
        "type": "InputVariableMap",
        "action": "action"
      },
      "configuration": {
        "dependsOn": [
          {
            "option": "action",
            "action": "CLEAR"
          }
        ]
      },
      "name": "input",
      "label": "Input Variables",
      "info": "The input variables passed to the (sub) action"
    },
    {
      "meta": {
        "type": "Output",
        "output": {
          "type": "Inherit",
          "action": "action"
        }
      },
      "name": "result",
      "label": "As",
      "info": "The resulting value of the (sub) action"
    }
  ],
  "yields": "NONE"
}