Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
I need to populate an order metafield with the paymentID from the successful transaction associated with the order. This code gets me close to the desired result, but it still includes blank line returns for every transaction that wasn't successful. I'm trying to use "strip" to remove the blank lines, but it doesn't change the result. I'm not sure if that's because the filter doesn't work in the same way within a flow, or if something else is wrong with my code.
Below the code are the current result, and the desired result within quotes. I've also considered adding a 2nd flow to just perform the desired formatting on the metafield, but I can't figure out how to do that either. Either approach (or something entirely new) would be fine, I just need to populate the metafield shortly after order entry.
Current code:
{% for transactions_item in order.transactions %}
{% if transactions_item.status == "SUCCESS" %}
{{transactions_item.paymentId | strip }}
{% endif %}
{% endfor %}
Current Result:
"
r6n2b4Rg3uJPvgtqgqs9oj
"
Desired Result:
"r6n2b4Rg3uJPvgtqgqs9oj"
@JimmyLaxHomeDepotSurvey wrote:I need to populate an order metafield with the paymentID from the successful transaction associated with the order. This code gets me close to the desired result, but it still includes blank line returns for every transaction that wasn't successful. I'm trying to use "strip" to remove the blank lines, but it doesn't change the result. I'm not sure if that's because the filter doesn't work in the same way within a flow, or if something else is wrong with my code.
Below the code are the current result, and the desired result within quotes. I've also considered adding a 2nd flow to just perform the desired formatting on the metafield, but I can't figure out how to do that either. Either approach (or something entirely new) would be fine, I just need to populate the metafield shortly after order entry.
Current code:
{% for transactions_item in order.transactions %}
{% if transactions_item.status == "SUCCESS" %}
{{transactions_item.paymentId | strip }}
{% endif %}
{% endfor %}
Current Result:
"
r6n2b4Rg3uJPvgtqgqs9oj"
Desired Result:
"r6n2b4Rg3uJPvgtqgqs9oj"
To achieve the desired result, you can use the assign tag to collect the paymentId values into a single variable and then output that variable. Here’s a revised version of your code:
{% assign payment_ids = "" %}
{% for transactions_item in order.transactions %}
{% if transactions_item.status == "SUCCESS" %}
{% assign payment_ids = payment_ids | append: transactions_item.paymentId %}
{% endif %}
{% endfor %}
{{ payment_ids | strip }}
This way, you append each paymentId to the payment_ids variable if the transaction status is "SUCCESS" and then output the final variable after the loop. This should give you the desired result without the extra blank lines.
Unfortunately I'm still not getting the desired result. The only change seems to be the line return at the very end of the field is gone, but there are still a number of blank lines at the start of the field. Below is what's being inserted into the metafield:
r6n2b4Rg3uJPvgtqgqs9oj
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025