Re: Formatting issue when copying metafield from Company to Order

Solved

Formatting issue when copying metafield from Company to Order

Polleke
Shopify Partner
7 0 3

When trying to update an Order metafield with the value copied from a Company metafield, I get the error: Got error updating metafield:
Value does not exist in provided choices: ["AAA", "BBB", "CCC"]." For value: "["BBB"]", Type: single_line_text_field

The value "BBB" is the correct output for this order, but it seems that Flow adds "[ ... ]", and next it's rejected for not matching my provided choices. How do I get rid of the "[ ... ]" eclosure?

Here is the liquid used in the value box
{%- for companyContactProfiles_item in order.customer.companyContactProfiles -%}
{%- for metafields_item in companyContactProfiles_item.company.metafields -%}
{%- if metafields_item.namespace == "custom" and metafields_item.key == "partner" -%}
{{ metafields_item.value }}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}

Screenshot of that code:

CleanShot 2024-04-22 at 12.30.25.png

Accepted Solution (1)

DaveMcV
Shopify Staff
104 31 29

This is an accepted solution.

Hi @Polleke,

 

Flow doesn't try to add any square brackets as part of that action so it is likely related to the input data. What type is the custom.partner metafield on the company? If it's a list of single line text values, that would explain why it is showing up like an array. 

 

If the input metafield is a list of single line text values and the output metafield is a single line text value, you'll need to use Liquid filters to transform the data from a stringified array into something that can be used in the single line text field. Because the source field looks like it's a list, there could be more than one value in the metafield. That is something you'd likely have to consider.

 

Hope that helps!

DaveMcV | Flow Development 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 3 (3)

DaveMcV
Shopify Staff
104 31 29

This is an accepted solution.

Hi @Polleke,

 

Flow doesn't try to add any square brackets as part of that action so it is likely related to the input data. What type is the custom.partner metafield on the company? If it's a list of single line text values, that would explain why it is showing up like an array. 

 

If the input metafield is a list of single line text values and the output metafield is a single line text value, you'll need to use Liquid filters to transform the data from a stringified array into something that can be used in the single line text field. Because the source field looks like it's a list, there could be more than one value in the metafield. That is something you'd likely have to consider.

 

Hope that helps!

DaveMcV | Flow Development 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.
Polleke
Shopify Partner
7 0 3

Hi Dave,
Thanks for pointing me in the right direction!

By mistake the partner metafield in Companies had been set up at single line text, multiple values.
The Order metafield partner was set up correctly as single line text, single value. Both use a validation list.

After we corrected the mistake with the Companies metafield, both metafields were configured exactly similar, and now Flow copies the partner value as intended to the order

DaveMcV
Shopify Staff
104 31 29

Hi @Polleke,

 

Glad you got it working!

DaveMcV | Flow Development 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.