Shopify Flow Automation • Update Product Metafield Value to (Nothing)

Solved

Shopify Flow Automation • Update Product Metafield Value to (Nothing)

journeylab
Shopify Partner
14 0 1

I am using a theme that generates custom badges when text is entered into a metafield (made of single-line text). When the metafield is empty, the custom badge will not display.

 

The only word that I would put in there is "preorder" but within Shopify Flow, I am unable to remove text in the VALUE field or leave it blank. 

 

Does anyone have a workaround for this?

 

Screenshot 2023-08-29 at 1.31.46 AM.png

Accepted Solution (1)
paul_n
Shopify Staff
1339 151 310

This is an accepted solution.

You can try Flow's "Remove Product Metafield" action. I think it will only work if the metafield doesn't have a "definition".  This the API that Flow calls that show's how to set a metafield and that the value field is required https://shopify.dev/docs/api/admin-graphql/2023-07/mutations/metafieldsSet

 

Regarding using something like "blank", you would need to update your theme to account for that.

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 9 (9)

journeylab
Shopify Partner
14 0 1

I tried this... but it returns telling me the field can't be blank.


{% assign newValue = '' %}

{{ newValue }}

paul_n
Shopify Staff
1339 151 310

The metafields API doesn't allow you to set blank values, so this isn't possible. You might want to consider using another strategy, like a reserved word such as "blank". 

 

You might also be able to remove the metafield entirely instead and then check if it's null. 

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.
journeylab
Shopify Partner
14 0 1

Hi Paul! 

 

So I am using a theme where custom badges are set only when there is text in a given metafield, but go away altogether when that text field is blank. 

 

This automation is inventory count-based, so when items reach an inventory of 0, "preorder" gets added to this field. 

 

I'm not entirely confident what a "reserved word such as blank" would entail, but that or removing the meta field entirely sounds good to me. 

 

Do you have a resource you might be able to share? 

paul_n
Shopify Staff
1339 151 310

This is an accepted solution.

You can try Flow's "Remove Product Metafield" action. I think it will only work if the metafield doesn't have a "definition".  This the API that Flow calls that show's how to set a metafield and that the value field is required https://shopify.dev/docs/api/admin-graphql/2023-07/mutations/metafieldsSet

 

Regarding using something like "blank", you would need to update your theme to account for that.

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.
journeylab
Shopify Partner
14 0 1

You're a genius! Thank you. I have it set up. I will test it over a longer period of time — but this looks promising! 

gary07
Excursionist
60 0 10

Hi Paul

 

Would you able to help to get the metaobject entries value

 

gary07_0-1726229988504.png

 

When I click on return data I am unable to find the entries as I need to select the entries from the list

 

 

gary07_1-1726230051760.png

 

Here is list of entries

 

gary07_2-1726230145923.png

 

 

 

paul_n
Shopify Staff
1339 151 310

 

Your 2 screenshots don't match. Which mutation are you using? 

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.
gary07
Excursionist
60 0 10

Hi

 

I am creating metaobject entries using metaobjectUpsert and now I want to update that value to meta field

 

 

Before I was using incorrect after research now I am using 

productUpdate 

 

problem is "value": "gid://shopify/Metaobject/54024470751",

I should get /metaobjects/entries/or_see_more_choices/54024470751

 

 

 

{
"input": {
"metafields": [
{
"id": "{{product.id}}",
"namespace": "custom",
"key": "or_see_more_choices_",
"value": "{{sendAdminApiRequest1.metaobject.id}}",
"type": "list.metaobject_reference"
}
]
}
}

gary07_0-1726237270256.png

 

paul_n
Shopify Staff
1339 151 310

You don't need to use the Send Admin API request to update a metafield. Just use "Update Product Metafield". Assuming it accepts a list of metaobjects, it needs to look like ["gid://shopify/Metaobjects/123","gid://shopify/Metaobjects/345"]

 

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.