JavaScript Date/Time functions not working in Run Code Action

Topic summary

Core Issue:
JavaScript’s new Date() function returns incorrect timestamps (e.g., 1970-01-04) when used in Shopify Flow’s Run Code action due to security limitations that prevent generating arbitrary dates.

Primary Solution:
Use existing date fields from Shopify objects instead of creating new dates:

  • For order-based flows: Query createdAt from the order object
  • For scheduled flows: Use scheduledAt from the workflow trigger
  • Access via GraphQL query and reference in code as input.order.createdAt

Key Limitations:

  • Random date generation is intentionally blocked for security
  • Date manipulation functions work once a real date is obtained from Shopify objects
  • Querying orders by metafield date values is not yet supported in the API (only text fields currently work)

Open Challenges:

  • Comparing current dates with order metafield dates remains difficult
  • No direct way to access “today’s date” without a trigger-provided timestamp
  • Users seeking to send delivery reminders based on metafield dates lack a clear solution

Resources:
Shopify provides code examples using scheduledAt in their Flow examples repository.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

Thanks Paul, yup, it seems so. Below are the 4 triggered Flow nodes in question:

The execution logs show the “Get metaobject entry” node correctly passes the value of start_date to the “Run code” node (last in the chain). I tried your idea of also passing “today” but get these errors:

  • Field ‘today’ doesn’t exist on type ‘Query’

  • Cannot query field “today” on type “Query”.