What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: Shopify Flow for Custom Attributes

Why isn't my custom Shopify Flow triggering with specific order attributes?

rsaberon
Shopify Partner
12 1 1

Howdy! 


I need help in creating Shopify Flow.

 

What I did

1.  Add  custom code that allows the customer to add a custom Gift Note on Checkout pages. I did use the cart.attributes feature, it's working perfectly right now.  

2. Here's the results in Order Details page, it shows the custom Cart attributes.

custom-notes.png

 

Issues: The Flow doesn't trigger

I did create a Custom Flow that will add the submitted data to Google Spreadsheet. Here's my conditions. 

  1. Order is Created
  2. If  Order Custom Attributes contains the Key, add the data to Google Spreadsheet

I think there's something wrong with my Custom Attributes conditions. Can someone please verify if the conditions are correct. Please check below.

custom-attributes.png

 

Any help is appreciated! Thanks!

 

 

Replies 7 (7)

rsaberon
Shopify Partner
12 1 1

Any one please help me on this?

evaldas_92
Shopify Partner
60 1 27

Hi,

  • I believe the first condition should be ( Key equals/includes "To" ) 
  • The second condition should be ( Key equals/includes "From" )
  • And the third condition should be ( Key equals/includes "Message" )

Note that you don not need to prefix these with "attributes", and that the keys may be case sensitive.

Alternatively, you can create a single condition where all of the custom attribute keys must match one of specified keys, like so (if you don't expect any other attributes to be available):

evaldas_92_0-1594365089657.png

 

kmt232
Visitor
1 0 3

This is also something I'm interested in. I cannot get my flow to work using customAttributes

vcc
Shopify Partner
1 0 1

This is 3 years later for a reply but if anyone is having this issue it is worth mentioning the 2023 solution.

 

@evaldas_92 is 100% correct, When using a condition for custom attributes, you will loop over them. the key is JUST the name of the attribute and NOT attribute[key]. If you are unsure, you can see the key's name when you click on the custom attributes on the order.

 

Now the main reason I posted this is that if you are trying to USE values in the order attributes, you need to know that Shopify Flow uses the GraphQL api. So reference: https://shopify.dev/docs/api/admin-graphql/ for the names in your code.

 

Secondly, you can use full liquid code in there to set a variable.

 

So if you can use

 

{%- liquid
assign theAttributeYouCareAbout = "defaultValue"
for attribute in order.customAttributes
  if attribute.key == "theAttributeKey"
    assign theAttributeYouCareAbout = attribute.value
    break
  endif
endfor -%}{{ theAttributeYouCareAbout }}

 

I have used this code and replaced the default value as well as the name of the attribute key and by storage variable in a working shopify flow.

 

Use as you see fit!

 

In the worst case if you can't sort it out using shoify flow, you can always create a custom private app with a webhook and write it in your language of choice (Python, Javascript..etc)

 

mikeraamro
Shopify Partner
1 0 0

Thank you both for posting this solution. To piggy back on this, is there a standard way to define the key for custom attributes when an underscore or dash is not used between words? For example, we have a custom attribute named "Customer Type" that we would like to add to a metafield using a flow. Does this need to be changed to something like "Customer_Type" in order to reference the key, in which case the full variable to reference this custom attribute would be {{order.customAttributes.Customer_Type}}, or is there another way to reference this without adding the underscores and dashes? And if there is, how can one determine the correct Key for a custom attribute with spaces?

 

I'm interested in excluding the dash and underscores because this is a field that the customer will see during checkout and on the invoice, and it looks less professional when the dashes and underscores have to be sued.

 

Thank you for any additional light someone can shed on this!

paul_n
Shopify Staff
1445 157 334

In Flow, you cannot access custom attributes like: {{order.customAttributes.Customer_Type}}

 

If you look at the code just above your post, it loops over custom attributes and checks the key. The same approach is currently used for 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.
haddi
Shopify Partner
17 1 3

No need to loop, the value of `Customer_Type` could be accessed using the `where` and `map` filters:

{{ order.customAttributes | where: 'key', 'Customer_Type' | map: 'value' }}

 

Mohamed, web developer.