Re: Metafield refering to Metaobject

How to display chosen metaobject name instead of URL in a metafield?

Viktor_T
Tourist
12 0 0

I have a Metafield referring to a metaobject(custom.typ_av_disc3). The metaobject have 5 different options to choose from. I want to print the name of the choosen option into another metafield with single text, so it can be an option in the setup of collections.

I have these code under "Update product metafield" in the flow app. But the only thing I get out is a long text string like the url.adress and not the name of the choice which has been done in the metafield, referring to the metobject, I just want the name of the choice and not the URL(or what it is).

 

{"value"=>"gid://shopify/Metaobject/18734612808", "namespace"=>"custom", "key"=>"typ_av_disc3"}


{%- assign typavdisc_metafield = product.metafields | where: "namespace", "custom" | where: "key", "typ_av_disc3" -%}
{{- typavdisc_metafield-}}

 

Do anyone know how I should write to only get the name of the chossen metaobject into the metafield?

Replies 3 (3)

paul_n
Shopify Staff
1342 151 310

That assign statement returns a list. So you need to change it to:

 

{%- assign typavdisc_metafield = product.metafields | where: "namespace", "custom" | where: "key", "typ_av_disc3" | first -%}

 

And to access the value you need:
{{- typavdisc_metafield.value -}}

 

I think that will output this: gid://shopify/Metaobject/18734612808.

 

 

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.
Viktor_T
Tourist
12 0 0

Thanks, but I want to print the name(Display name) of the choosen Metaobject value.

The value I get out referring to the first(?) in the metaobject list(emtries) and not the choosen in the metafield(I have 6 different entries in the metaobject to choose from)

paul_n
Shopify Staff
1342 151 310

This would output the field key and value for any Metaobject fields

{% for metafields_item in product.metafields %}
{% for fields_item in metafields_item.reference.Metaobject.fields %}
{{fields_item.key}}--{{fields_item.value}}
{% 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.