Add free (discounted 100%) item to new orders

Topic summary

A user encountered an error while implementing a Shopify Flow template designed to add a free (100% discounted) item to new orders. The error occurred because location_inventory was returning as undefined.

Root Cause:

  • The template code searches for a location by name using the placeholder text ‘Enter a unique part of the location name here’
  • The user hadn’t replaced this placeholder with their actual location name

Solution:

  • Edit the template code to substitute the placeholder with the actual location name
  • Consider adding null/undefined checks when working with JavaScript data arrays

Status: Resolved after the user updated the location name in the code.

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

I’m using this flow template but am getting this error when running:

I crossed out the location but it does return a correct name. I didn’t change anything in the template.

Can someone tell me why/how to fix the error?

Thanks in advance!

1 Like

Your post is missing the most important part of all - the console.log output. Based on the available information, location_inventory is probably undefined, which means no item in the array met your criteria.

It’s a good idea to check for null/undefined when working with data in JavaScript.

In that code, it’s finding a location by it’s name (‘Enter a unique part of the location name here’). You need to substitute the name of your location there.

Thank you! That worked. Silly me didn’t realize I was suppose to edit that. :sweat_smile: