We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Updating Custom Metafields : adding values

Updating Custom Metafields : adding values

divyaneelam
Visitor
1 0 0

Hello Shopify Community,

 

I’m working on a task where I need to update a custom integer customer metafield when an order is created and has the tag “fulfilled”.

 

Here’s what I’ve done so far:

 

1. Created the Customer Metafield:

• Name: custom

• Namespace and Key: custom.orders

•Type: Integer


Screenshot 2024-07-21 at 19.47.18.png

 

2. Set Up Shopify Flow:

Trigger: Order Created.

Condition: Check if Order Tags contains “fulfilled”.

Action: Update the customer metafield custom.orders by incrementing its value by 1.

 

However, when setting up the flow, I encountered the following error: "custom" is invalid. Replace this variable.

 

Detailed Steps in Shopify Flow:

 

1. Trigger: Order Created.

2. Condition: Order Tags contains “fulfilled”.

3. Action: Update Customer Metafield:

• Namespace: custom

• Key: custom.orders

• Value: {{ order.customer.metafields.custom.custom.orders | default: 0 | plus: 1 }}

•Type: Integer

 

Error Encountered:

 

The specific error message I’m receiving is:

"custom" is invalid. Replace this variable.

Screenshot 2024-07-21 at 19.55.59.png

Request for Assistance:

 

Can anyone help me understand what might be causing this error and how I can resolve it? Any advice on the correct setup or common pitfalls to avoid would be greatly appreciated.

 

Thank you in advance for your help!

 

Additional Information:

 

•I’m using Shopify Plus.

•The goal is to track the number of fulfilled orders for each customer using a custom metafield.

Replies 2 (2)

PaulNewton
Shopify Partner
8031 688 1649

Hi @divyaneelam 👋Thanks you so much for the great detail of your issue, very refreshing to see.

 

The key is "orders" NOT "custom.orders" "custom" is the namespace , based on the description and 2nd image showing the value of the flow actions key field and error message.

So it's {{ order.customer.metafields.custom.orders | default: 0 | plus: 1 }} , NOT "{{ order.customer.metafields.custom.custom.orders | default: 0 | plus: 1 }}"

⚠️You may also need to use the .value property for some metafield types {{ order.customer.metafields.namespace.key.value }}

 

I also recommend doing the hard work of naming things for better contexts now or in the future.

You want to be able to use metafields verbally or describing business logic without ambiguities.

 

Renaming it to something like reporting.fulfilled_orders_count , or stats.fulfilled_orders_count  , fulfillment.fulfiled_orders_count etc.

Something that makes sense for the purpose of what's being made as a statement.

 

As you grow custom.orders kinda implies that some custom order action has occurred,  such as an order was edited by staff or product personalization ,  for all the orders in that metafields orders value, but the values aren't actually "orders" objects or id references it's just a number count.

The custom thing is just a placeholder when metafields are being made and a clue better naming is warranted.

 

 

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


paul_n
Shopify Staff
1828 199 435

Metafields cannot be accessed the same way in Flow as they are in theme liquid (using something like order.namespace.key).

 

To access a single metafield value, you click "Add a variable" and then click find the "metafield" variable (note: not the plural metafields). It will guide you to choose your metafield and add it to the environment. 

 

Once you do that, Flow stores that metafield type for the workflow and it will be accessible to other steps as a variable in the picker.

 

Doc page that outlines this: https://help.shopify.com/en/manual/shopify-flow/reference/metafields#get-metafield-data

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.