January 31, 2024

Shopify Flow - New Run code action

You can now use a new Run code action in Flow. In the action, you can write JavaScript code to return data into a workflow based on the inputs and your code.

Code example that outputs a metafield string

The Run code action makes it possible to do many things that were not possible before. Common use case include:

  • Counting the number of certain types of items in a list
  • Computing the value for complex metafields like lists
  • Transforming data like dates and numbers so that they can be used in conditions

Your code can leverage any data provided by prior steps in the workflow in order to execute the code. These inputs are specified as a GraphQL query, and are available as JSON objects to your code. Your code will typically return one or more output variables. You can return simple scalars, lists, and objects. So that subsequent actions know what the code can return, you will specify the output as a GraphQL type.

To give it a try, you can build a workflow from scratch in Flow, or use a template. Additionally, you can see some example code snippets in a public GitHub repository.

For more information about how it works, limitations, and upcoming improvements, go to the documentation. For questions and feedback, you can post to the Shopify community.