Question for easy flow setup regarding line item variant metafield value.

bear42
Shopify Partner
61 0 6

Can anyone help with the liquid for a quite basic flow i am trying to setup.
I need the value of a variant metafield with curtain namespace & key, to be tagged to an order.

For example;
"trigger" Order is created
"Filter" Line items is tagged with "preorder"
"Execution" Add order tag = X (value of variant meta field smartpack.exp-date)

Skærmbillede 2024-04-03 kl. 18.12.38.png

Replies 20 (20)

paul_n
Shopify Staff
1005 133 240

Right now we recommend doing looping such as here:

https://community.shopify.com/c/shopify-flow-app/shopify-flow-value-from-custom-customer-metafield-i...

 

We do have an update coming that will make accessing metafields more straight-forward and not require looping unless the metafield is 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.
bear42
Shopify Partner
61 0 6

Hi paul,

When is this update coming, and would we be able to access a beta, if we are shopify plus customers?

Or can you give me the direct liquid i should put in to access the value of a line item variants meta field called 
Namespace: smartpack
Key: expected-date

paul_n
Shopify Staff
1005 133 240

There won't be a beta - it will be generally available. 

 

If you use "add a variable" to choose "order / lineItems / variant / metafields / namespace" Flow will insert the loop you need. You then add a condition to check the namespace and key and output the values. Something like:

{%- for li in order.lineItems -%}
{%- for mf in li.variant.metafields -%}
{%- if mf.namespace == "smartpark" and mf.key == "expected-date" -%}
{{- mf.value -}}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
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.
bear42
Shopify Partner
61 0 6

Hi Paul,

I am tring but givin me error, can you check if you can find what i am doing wrong here?




36d2b6a698f815a33a4100f1517d1c04e300bfd720da387eca5589d0488ef0d9:{"__metadata":{"version":0.1},"root":{"steps":[{"step_id":"018ead99-fb68-7186-b27c-04ab0dbcaf0c","step_position":[900,1220],"config_field_values":[],"task_id":"shopify::admin::order_created","task_version":"0.1","task_type":"TRIGGER","description":null,"note":null,"name":null},{"step_id":"018ead99-fb68-797c-bbbb-f38576a7b169","step_position":[1260,1220],"config_field_values":[{"config_field_id":"condition","value":"{\"uuid\":\"0cd098fa-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"0cd098f0-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098fa-f329-11ee-a43f-1dc8a70f3d44\",\"array_path\":{\"uuid\":\"0cd098f1-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f0-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"order.lineItems\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"array_item_key\":{\"uuid\":\"0cd098f2-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f0-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"operation\":{\"uuid\":\"0cd098f3-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f0-f329-11ee-a43f-1dc8a70f3d44\",\"array_path\":{\"uuid\":\"0cd098f4-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f3-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item.variant.metafields\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"array_item_key\":{\"uuid\":\"0cd098f5-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f3-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"operation\":{\"uuid\":\"1df6db38-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f3-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"0cd098f7-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db38-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"0cd098f8-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f7-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item.namespace\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"metafields_item.namespace\"},\"rhs\":{\"uuid\":\"401daf40-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"0cd098f7-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"smartpack\",\"comparison_value_type\":\"LiteralValue\"},\"value_type\":\"EnvironmentScalarDefinition:String\",\"operator\":\"==\",\"operation_type\":\"Comparison\"},\"rhs\":{\"uuid\":\"1df6db31-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db38-f329-11ee-a43f-1dc8a70f3d44\",\"array_path\":{\"uuid\":\"1df6db32-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db31-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item.variant.metafields\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"array_item_key\":{\"uuid\":\"1df6db33-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db31-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"\"},\"operation\":{\"uuid\":\"2983b453-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db31-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"1df6db35-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"2983b453-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"1df6db36-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db35-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item.key\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"metafields_item.key\"},\"rhs\":{\"uuid\":\"3e9d02b0-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"1df6db35-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"po-qty\",\"comparison_value_type\":\"LiteralValue\"},\"value_type\":\"EnvironmentScalarDefinition:String\",\"operator\":\"==\",\"operation_type\":\"Comparison\"},\"rhs\":{\"uuid\":\"2983b450-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"2983b453-f329-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"2983b451-f329-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"2983b450-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"metafields_item.value\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"metafields_item.value\"},\"rhs\":{\"uuid\":\"4e9aabd0-f58c-11ee-b75f-4bcf40c11e1f\",\"parent_uuid\":\"2983b450-f329-11ee-a43f-1dc8a70f3d44\",\"value\":\"\",\"comparison_value_type\":\"LiteralValue\"},\"value_type\":\"EnvironmentScalarDefinition:String\",\"operator\":\"not_empty_and_not_nil?\",\"operation_type\":\"Comparison\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"},\"operator\":\"ANY\",\"operation_type\":\"ArrayExpression\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"},\"operator\":\"ANY\",\"operation_type\":\"ArrayExpression\"},\"operator\":\"ANY\",\"operation_type\":\"ArrayExpression\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"}"}],"task_id":"shopify::flow::condition","task_version":"0.1","task_type":"CONDITION","description":"Works because even tho it will still in theory activate on orders after the expected date, these will not be sellable as continue overselling is off","note":null,"name":null},{"step_id":"018ead99-fb68-715e-9c7a-309510af8ebd","step_position":[1900,1480],"config_field_values":[{"config_field_id":"order_id","value":"order.id"},{"config_field_id":"tags","value":"[\"{% for lineitems_item in order.lineItems %} {% for metafields_item in lineitems_item.variant.metafields %} {% if metafields_item.namespace == \\\"smartpark\\\" and metafields_item.key == \\\"expected-date\\\" %} {{ metafields_item.value }} {% endif %} {% endfor %} {% endfor %}\"]"}],"task_id":"shopify::admin::add_order_tags","task_version":"0.1","task_type":"ACTION","description":null,"note":null,"name":null},{"step_id":"6f95c490-f330-11ee-a43f-1dc8a70f3d44","step_position":[1620,1220],"config_field_values":[{"config_field_id":"condition","value":"{\"uuid\":\"87a21437-f330-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"87a21430-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21437-f330-11ee-a43f-1dc8a70f3d44\",\"array_path\":{\"uuid\":\"87a21431-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21430-f330-11ee-a43f-1dc8a70f3d44\",\"value\":\"order.lineItems\",\"comparison_value_type\":\"EnvironmentValue\"},\"array_item_key\":{\"uuid\":\"87a21432-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21430-f330-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item\",\"comparison_value_type\":\"EnvironmentValue\"},\"operation\":{\"uuid\":\"87a21433-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21430-f330-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"87a21434-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21433-f330-11ee-a43f-1dc8a70f3d44\",\"lhs\":{\"uuid\":\"87a21435-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21434-f330-11ee-a43f-1dc8a70f3d44\",\"value\":\"lineItems_item.variant.inventoryQuantity\",\"comparison_value_type\":\"EnvironmentValue\",\"full_environment_path\":\"lineItems_item.variant.inventoryQuantity\"},\"rhs\":{\"uuid\":\"9263ae10-f330-11ee-a43f-1dc8a70f3d44\",\"parent_uuid\":\"87a21434-f330-11ee-a43f-1dc8a70f3d44\",\"value\":\"0\",\"comparison_value_type\":\"LiteralValue\"},\"value_type\":\"EnvironmentScalarDefinition:Int\",\"operator\":\"<\",\"operation_type\":\"Comparison\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"},\"operator\":\"ANY\",\"operation_type\":\"ArrayExpression\"},\"operator\":\"AND\",\"operation_type\":\"LogicalExpression\"}"}],"task_id":"shopify::flow::condition","task_version":"0.1","task_type":"CONDITION","description":null,"note":null,"name":null}],"links":[{"from_step_id":"018ead99-fb68-7186-b27c-04ab0dbcaf0c","from_port_id":"output","to_step_id":"018ead99-fb68-797c-bbbb-f38576a7b169","to_port_id":"input"},{"from_step_id":"018ead99-fb68-797c-bbbb-f38576a7b169","from_port_id":"true","to_step_id":"6f95c490-f330-11ee-a43f-1dc8a70f3d44","to_port_id":"input"},{"from_step_id":"6f95c490-f330-11ee-a43f-1dc8a70f3d44","from_port_id":"true","to_step_id":"018ead99-fb68-715e-9c7a-309510af8ebd","to_port_id":"input"}],"patched_fields":[],"workflow_name":"Auto tag preorder, with delivery date (preorder setup)"}}

 

paul_n
Shopify Staff
1005 133 240

I can't import that. What error are you getting?

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.
bear42
Shopify Partner
61 0 6

This issue:

bear42_0-1712583823546.png

 

paul_n
Shopify Staff
1005 133 240

Looks like you didn't set up the condition correctly. Can you share an image of your condition panel with the side panel open?

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.
bear42
Shopify Partner
61 0 6

Here is condition:

bear42_1-1712585363945.png

 


i put in this as tag:

{% for lineitems_item in order.lineItems %} {% for metafields_item in lineitems_item.variant.metafields %} {% if metafields_item.namespace == "smartpark" and metafields_item.key == "expected-date" %} {{ metafields_item.value }} {% endif %} {% endfor %} {% endfor %}

bear42_0-1712585340518.png

 

paul_n
Shopify Staff
1005 133 240

The issue

 

For that second condition, you need to delete it. When you re-add it, be sure to choose the "Add criteria for same item" right under the first metafield condition (like you add before) and then make sure to select the "metafields_item / key" and NOT variants / metafields /key 

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.
bear42
Shopify Partner
61 0 6

Nice, testing it out now if the liquid for the Tag is correct. 

bear42
Shopify Partner
61 0 6

I tried putting this liquid for the "add order tags"

{% for mf in order.metafields %} {% if mf.namespace == "smartpack" and mf.key == "po-qty" %} {{ mf.value}} {% endif %}{% endfor %}

But it is not adding any tag at all.

As mentioned, i would like it to add the Value of variant meta field smartpack.po-qty to a order tag.

Hope you can help.
paul_n
Shopify Staff
1005 133 240

That is an order metafield not a variant metafield. you need order / lineItems / variant / metafields

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.
bear42
Shopify Partner
61 0 6

I see what you mean, but can you be more specific?

Does it not have to be a Liquid code when i try to add an order tag?

What to do after the / metafields? How am i sure it uses the specfic value from a specfic metafield i tell it.

Please if you can be more specfic would be amazing

paul_n
Shopify Staff
1005 133 240

I already gave you the code above. 

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.
bear42
Shopify Partner
61 0 6

Hi paul,

So i tried inputting your code above:
{%- for li in order.lineItems -%} {%- for mf in li.variant.metafields -%} {%- if mf.namespace == "smartpark" and mf.key == "expected-date" -%} {{- mf.value -}} {%- endif -%} {%- endfor -%} {%- endfor -%}


And of course adapted the mf to metafields_item etc

Sadly it does not add any tag, even tho the flow is run succesfully. 

Only time i get some output, is when i follow the classic tag liquid path. </>

bear42_0-1712929953446.png


Is there any way where you can make this flow how it should be, and download the file and send it to me. 
So close to get it working. 

paul_n
Shopify Staff
1005 133 240

Most likely one of two things is happening:

- Flow is never getting to the action due to your conditional logic (look at the workflow run to verify)

- You have the wrong namespace or key

 

Assuming the latter, use the Log output action with the same code. It will print out the value. You can add other things to the code so you see what Flow sees, for example I might use:
{%- for li in order.lineItems -%}

{%- for mf in li.variant.metafields -%}

{{mf.namespace}}::{{ mf.key }}::{{mf.value}}

{%- if mf.namespace == "smartpark" and mf.key == "expected-date" -%} {{- mf.value -}} {%- endif -%} {%- endfor -%} {%- endfor -%}

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.
bear42
Shopify Partner
61 0 6

It is running the flow successfully, and i confirmed that it can actually tag when i do the classic way: order / lineItems / variant / metafields

bear42_0-1712931837367.png


But it stops working if i add custom code to that liquid code, like the stuff you sent above.

It is like it can not filter at all. 

Again, is it possible for you to do an example flow that would work, and i could get the file to see it working?

paul_n
Shopify Staff
1005 133 240

My giving you a workflow isn't going to help because you have the wrong namespace or key entered there, or it's not available on any of the variants. 

 

FYI, the key in your condition is different than the key in the code. If you put that code I just gave you into a log output action, you will see all the metafields on the variants.

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.
bear42
Shopify Partner
61 0 6

The condition was not the problem, the problem was as simple as you had put smartpark and not smartpack.
Now everything works.

All good mate, thank you so much for the help.

paul_n
Shopify Staff
1005 133 240

🤣 Glad you got there!

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.