Display Variant Metafield value in a for loop?

amanda-91
Shopify Partner
82 0 45

I'm trying to setup a "send internal email" action which includes details of items in a fulfillment order, outputted into a table with columns listing each included variant's order-qty - SKU - variantTitle. I also need to include each variant's value for a particular metafield, but can't get this one to not kick an error. It looks like the metafields variable section has been deprecated in Flow as of January 2023, but I can't figure out the syntax to get even those to work.

 

Can anyone help me figure out what the value should be to output the value for variant.metafields.inventory.supplier_sku next to the ️in the code below? I am getting an error reading:  "variant" is invalid. Replace this variable.

 

<table>
<thead>
    <tr>
      <th>QTY</th>
      <th>SKU</th>
      <th>SKU-SUP</th>
      <th>ITEM</th>
    </tr>
  </thead>
  <tbody>
    {% for lineItems_item in fulfillmentOrder.lineItems %}
      {%- if lineItems_item.requiresShipping == 'true' -%}
        <tr>
          <td>{{lineItems_item.remainingQuantity}}</td>
          <td>{{lineItems_item.sku}}</td>
          <td>❗️{{lineItems_item.variant.metafields.inventory.supplier_sku}}</td>
          <td>{{lineItems_item.variantTitle}}</td>
        </tr>
      {%- endif -%}
    {% endfor %}
  </tbody>
</table>

 

Replies 3 (3)

paul_n
Shopify Staff
916 127 221
{{lineItems_item.variant.metafields.inventory.supplier_sku}}

The issue isn't the variant but the metafields. You cannot use dot notation in Flow to access metafields yet. Instead, you need to loop over them or use where like this:

{% assign mf = lineItems_item.variant.metafields | where: "namespace","inventory" | where: "key", "supplier_sku" | first %}
{{ mf.value }}
Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
amanda-91
Shopify Partner
82 0 45

Thanks Paul - I've tried adding that code to the <td> but am still getting the error: "variant" is invalid. Replace this variable.

paul_n
Shopify Staff
916 127 221

Oh, I see. The lineItem provided by that trigger is on a fulfillmentOrder and is not the same as the lineItem on the Order. For some reason the "variant" field is deprecated on that lineItem so cannot be used in the workflow.  See docs here: https://shopify.dev/docs/api/admin-graphql/2023-04/objects/FulfillmentOrderLineItem

 

I'm not sure exactly what you need to do here, but you could instead get the lineItems for the whole order by using fulfillmentOrder / order / lineItems / variant. 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.