Solved

adding metafield information from prefixed tags

jake_mitchell
Shopify Partner
120 2 50

Hi, 

 

We use a number of tags with prefixes. Some examples are: 

 

- 'brand_{brand}' , for example 'brand_nike'

- 'size: {size}', for example 'size: 32'

 

The filtering app we use currently has functionality to recognise the prefix and include everything after it as a filter option. e.g. for brand_nike it would ignore brand_ and just include 'nike'.

 

We can't move entirely over to just entering metafields for things like this for a number of reasons, so would like to add data to product metafields using flow. Some of this is about our listing integration but also because we can't do away with tags entirely because you can't make a collection based on metafields. 

 

The question is: 

 

Is there a way in Shopify flow to recognise when a certain tag prefix has been added and then add the tag info that follows the prefix into a metafield. 

 

For example: 

 

I add a product to the store with tag of brand_nike

 

The flow would work like

- Trigger = product added to store

- Condition = product tags include 'brand_'

- Action = add everything after 'brand_' to {metafield}

thanks

Accepted Solution (1)

paul_n
Shopify Staff
850 122 205

This is an accepted solution.

Hi Jake,

 

Yes you can do what you suggested there. I think this would be a useful template in Flow, so we'll create one to show how to do it. Two considerations:

- There is no "product/updated" or "product tag updated" trigger yet in Flow, which means the above will only run at creation time. There is also a "Product status changed" trigger that would fire as it moves from draft to active (and other changes to status). Also, with product added to store, you could manually run that workflow on existing products to backfill the metafields. Go to the admin and choose the products and look under "More actions" for "Run Flow automation"

 

In the action, you'll need to use liquid to strip the "brand_" part and get the value to add to the metafield value field. Something like:

{% for tag in product.tags %}{% if tag contains "brand_" %}{{ tag | remove: "brand_" }}{% endif %}{% 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.

View solution in original post

Replies 14 (14)

paul_n
Shopify Staff
850 122 205

This is an accepted solution.

Hi Jake,

 

Yes you can do what you suggested there. I think this would be a useful template in Flow, so we'll create one to show how to do it. Two considerations:

- There is no "product/updated" or "product tag updated" trigger yet in Flow, which means the above will only run at creation time. There is also a "Product status changed" trigger that would fire as it moves from draft to active (and other changes to status). Also, with product added to store, you could manually run that workflow on existing products to backfill the metafields. Go to the admin and choose the products and look under "More actions" for "Run Flow automation"

 

In the action, you'll need to use liquid to strip the "brand_" part and get the value to add to the metafield value field. Something like:

{% for tag in product.tags %}{% if tag contains "brand_" %}{{ tag | remove: "brand_" }}{% endif %}{% 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.
paul_n
Shopify Staff
850 122 205

Here's a link to the template: https://shopify.com/admin/apps/flow/web/editor/templates/908286d2-3e4c-4d9d-8e28-3cf9b12db4df

 

If that doesn't work, look for the one titled, "Update a product metafield if a product tag has a certain prefix"

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.
floridagifts
Tourist
3 0 0

Hi Paul,

 

I have been attempting to get this flow working on my store, but I keep getting this error- Got error updating metafield: "Value must be a single line text string." For value: " "

 

I contacted Plus support earlier today but they couldn't figure it out and had to submit a ticket to the flow team. This Flow would save me HUUUUUUUUGGGGGGEEEEE amounts of time.  I would really love to get this up and running.

jake_mitchell
Shopify Partner
120 2 50

Hi @floridagifts 

I'm no great expert but I was able to get this one working. 

Are you able to copy in the flow here (screenshots or copying the logic of the step that isn't working) and I'm happy to take a look.

jake_mitchell
Shopify Partner
120 2 50

Full disclosure though, I'm actually looking to move in the opposite direction. i.e. we set up metafields with set options that limit the chance of human error. we then have a flow that instead of creating the metafield form a tag creates a tag from the metafield. 

I've got that one working too and for our use case is a better way round of doing it. 

paul_n
Shopify Staff
850 122 205

@floridagifts wrote:

Hi Paul,

 

I have been attempting to get this flow working on my store, but I keep getting this error- Got error updating metafield: "Value must be a single line text string." For value: " "

 

I contacted Plus support earlier today but they couldn't figure it out and had to submit a ticket to the flow team. This Flow would save me HUUUUUUUUGGGGGGEEEEE amounts of time.  I would really love to get this up and running.


This means the value that you are putting into the metafield value was an empty string or white space. What liquid are you using in that value field?

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.
ali303
Tourist
10 0 4

Hi Paul,

 

I'm also experiencing an error when trying to use the 'Update a product metafield if a product tag has a certain prefix' Flow template.

 

All I have done is change the trigger to "Start when: Product status updated" and then "Check if: Tags starts with brand_".

 

In the "Update product metafield" action I have:

 

Metafield namespace: custom

Metafield key: brand

 

Value: {% for tags_item in product.tags %}{% if tags_item contains "brand_" %}{{ tags_item }}{% break %}{% endif %}{% endfor %}

 

Type: Single line text

 

When the Flow runs, I get the following error: Got error updating metafield: "Value must be a single line text string." For value: " "

 

I'm sure that I must be missing something super simple for it to be suggesting that there is a blank somewhere (or data missing), but I have struggled to find any documentation to try and help me along with this. Please could you kindly advise?

 

For a Flow template that requires a bit more input than the usual triggers and conditions it would be really helpful to newcomers to metafields (such as myself) if there could be a few more pointers or guidance available. We're hoping to move away from tags and over to metafields in the coming months and getting this Flow to work would be a great step in the right direction.


Thanks for your help.

paul_n
Shopify Staff
850 122 205

Try:

{% for tags_item in product.tags %}{% if tags_item contains "brand_" %}{{- tags_item -}}{% break %}{% endif %}{% endfor %}

The hyphens remove whitespace (including new lines).  It's also possible that this metafield requires a value. If so you might need to add a condition to check for when no tags match and then add a value like "no_brand"

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.
ali303
Tourist
10 0 4

Hi Paul, I really appreciate you getting back to me regarding this. I've tried the updated code, but unfortunately I get the same error message of "Value must be a single line text string." For value: " "

 

It's worthing noting that I'm testing this Flow using a single product that I know meets the criteria (i.e. it has a "Brand_..." tag) and so it meets the requirements for the Update product metafield action to be run. I'm simply changing the product's status each time the Flow is modified in order to trigger the Flow and hopefully get a successful result that can then be applied to the rest of our catalogue, but no luck just yet unfortunately!

 

Thanks again and, if you have any other suggestions, please let me know.

paul_n
Shopify Staff
850 122 205

Sorry, thinking about this more, the previous suggestion helps but the wrong issue. Here, you don't have any tags at all, so it won't even get to the part with it tries to output the tag. You might need to share a picture of the whole workflow to troubleshoot further because something is happening elsewhere. 

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.
ali303
Tourist
10 0 4

Hi Paul, thank you for your help.

 

Please see the screenshot below. I have installed the "Update a product metafield if a product tag has a certain prefix" template, replaced 'prefix_' with 'brand_' in the "Check if..." box, entered the relevant Metafield Namespace and Key date, and then replaced 'prefix_' with 'brand_' within the liquid code within the Value box.

 

Changing the status of a suitable product then results in the Flow being triggered, it successfully completes the "Check if..." stage but then provides the following error when it reaches the "Update product metafield" stage: ""Value must be a single line text string." For value: " ""


Thanks again.

 

Screenshot 2023-01-05 at 16.58.57.png

paul_n
Shopify Staff
850 122 205

I can't tell much from that, but I created a support ticket. Please share a link to the workflow run where you are seeing that message. The support ticket should get routed to me.

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.
paul_n
Shopify Staff
850 122 205

Just following up here from a DM, the issue I believe is that liquid conditions and text are case sensitive, whereas Flow conditions are not. So "Brand_" was passing the condition check for "brand_" but not the liquid check for {% if tag contains "brand_" %}. The solution is to use the exact case or cast it to all uppercase or lowercase.

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.

BigStart
Shopify Partner
5 0 0

Hello 👋,

 

It's been some time but this might still be needed by someone else.

 

We've just launched our app "Copytag - Tags to metafields". It simply copies product tags to metafields. Groups and jobs can be defined by prefixed tags and they can be running automatically. 

 

Here is a link to the app: https://apps.shopify.com/copytag.

 

And here is a short preview of what it does: https://www.youtube.com/watch?v=Y3z1CuRv1uY.

 

Don't hesitate to contact us at hey@bigstart.io if you have any questions for the app.