Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Why is boolean Metafield update not working (when strings do)?

Solved

Why is boolean Metafield update not working (when strings do)?

no_robotocha
Shopify Partner
56 2 16

I'm building a checkout UI extension and am able to update the order metafield using a string ("Yes" or "No") with the following code:

const checkValue = value ? "Yes" : "No"; 
applyMetafieldsChange({ type: "updateMetafield", namespace: metafieldNamespace, key: metafieldKey, valueType: "string", value: checkValue, });

 

However, trying to update a different, boolean,  metafield with the following settings does not work:

 

applyMetafieldsChange({
          type: "updateMetafield",
          namespace: metafieldNamespace,
          key: metafieldKey,
          valueType: "boolean",
          value,
        });

 

The metafields and toml are correctly set up with both metafield's namespace / key. The value on the latter code comes from the props of the onChange attribute, whereas on the former code uses this value with a ternary operator to convert to strings.

 

Why does the second one not update the metafield? Am I missing something?

 

Thanks!

 

--
No, Robotocha!
Accepted Solution (1)

SBD_
Shopify Staff
1831 273 422

This is an accepted solution.

Hey @no_robotocha 

 

The applyMetafieldsChange function currently only supports 'integer', 'string', and 'json_string' as value types. As a workaround you could consider storing it as a string or integer and then converting it back to a boolean in your code.

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 3 (3)

SBD_
Shopify Staff
1831 273 422

This is an accepted solution.

Hey @no_robotocha 

 

The applyMetafieldsChange function currently only supports 'integer', 'string', and 'json_string' as value types. As a workaround you could consider storing it as a string or integer and then converting it back to a boolean in your code.

Scott | Developer Advocate @ Shopify 

no_robotocha
Shopify Partner
56 2 16

Okay great, using a string and dealing with it programmatically later is exactly what I've done but I'm happy to know the reason for my issue! Thanks @SBD_ - Do you know where I could read more about the functions, I've had a look and can't seem to find them other than references within guides. 

--
No, Robotocha!
SBD_
Shopify Staff
1831 273 422

Great!

 

Yeah they're tricky to find. I only came across these references. We could do a better job with this.

Scott | Developer Advocate @ Shopify