Limit metafield results to only latest value

Solved

Limit metafield results to only latest value

FePixie
Shopify Partner
30 2 7

I'm updating an order metafield from product metafields...

this code works - however it returns all the old metafield values and not just the current value

 

 

 

{% for lineItems_item in order.lineItems %}
{% for metafields_item in lineItems_item.product.metafields %}
{% if metafields_item.key == 'eta' %}
 {{lineItems_item.name}} - {{metafields_item.value}}, 
{% endif %}
{% endfor %}
{% endfor %}

 

 

 

 how do i return just the current metafield value of each product? (instead of listing all the values the field has ever had)

Accepted Solution (1)

paul_n
Shopify Staff
1313 148 299

This is an accepted solution.

That question doesn't make sense as it doesn't output prior values. It could be outputting another variable if you have another metafield with a key of "eta" (in a different namespace).  Or it could be that your value is actually a list

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.

View solution in original post

Replies 4 (4)

paul_n
Shopify Staff
1313 148 299

This is an accepted solution.

That question doesn't make sense as it doesn't output prior values. It could be outputting another variable if you have another metafield with a key of "eta" (in a different namespace).  Or it could be that your value is actually a list

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.
FePixie
Shopify Partner
30 2 7

Then how do you suggest it managed to end up with 4 results on an order with only 2 items, clearly listing 2 different results for each item?  And the 'Arriving late December' bit an old value for the item?

FePixie_0-1712180230930.pngFePixie_1-1712180430723.png

 

FePixie
Shopify Partner
30 2 7

ok - i found it - there is an old metafield with no definition with an eta key - it must have come from there i guess - how can i delete the old metafield?  i dont see a delete button on it?

paul_n
Shopify Staff
1313 148 299
If you check for the namespace too in the condition you don’t need to
delete.

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.