Inconsistent results with conditional display of address variables

Solved

Inconsistent results with conditional display of address variables

amanda-91
Shopify Partner
84 0 48

I am getting inconsistent results with a flow to conditionally display "company" and "address2" values ONLY when present in a shipping address.

 

For a test order, I am getting the correct results when fulfilling but other orders such as the live one in screenshot are including blank linkes for these fields even though values for "company" and "address2" are NOT present in the shipping addresses. This is with the same liquid conditional:

 

{{ fulfillmentOrders_item.destination.firstName | capitalize }} {{ fulfillmentOrders_item.destination.lastName | capitalize }}
{%- if fulfillmentOrders_item.destination.company != blank -%}
  <br>{{ fulfillmentOrders_item.destination.company }}
{%- endif -%}
<br>{{ fulfillmentOrders_item.destination.address1 }}
{%- if fulfillmentOrders_item.destination.address2 != blank -%}
  <br>{{ fulfillmentOrders_item.destination.address2 }}
{%- endif -%}
<br>{{ fulfillmentOrders_item.destination.city }}, {{ fulfillmentOrders_item.destination.province }} {{ fulfillmentOrders_item.destination.zip }}
{%- if fulfillmentOrders_item.destination.countryCode != 'US' -%}
  <br>{{ order.shippingAddress.country }}
{%- endif -%}
<br>{{ fulfillmentOrders_item.destination.phone }}

 

I've spent a lot of time now trying to figure this out and it's frustrating when the test results show success but then real orders are still glitching despite identical code being applied to both. Can anyone help me understand why this code is leaving blank lines for "company" and "address-2" in live orders but not test orders?


Results:

IMG_1563.jpeg

  

IMG_1564.jpeg

Accepted Solution (1)
paul_n
Shopify Staff
1172 143 276

This is an accepted solution.

That second screen shot helps. I suspect your blank fields are coming through with spaces, so it passes the blank check and outputs an empty line. You could use something like:
{% assign my_address = fulfillmentOrder_item.destination.address2 | strip %}

{% if my_address != blank %}{{ my_address }}{% endif %}

 

Another way to do this would be to find and replace all spaces with something you can see (like "X"). That would help troubleshoot. 

 

If you are handy with code, you could also use the GraphiQL app to quickly write a query that gets this data. This is what I do when I suspect whitespace is causing a problem. In the API, it will return in quotes so you can sort of see the spaces. 

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 4 (4)

paul_n
Shopify Staff
1172 143 276

This has nothing to do with test vs live. The data is different. It's hard to tell how it's different as what you've provided isn't complete. 

 

I would try testing the liquid on the whatever order caused the above to happen according to this doc: https://help.shopify.com/en/manual/shopify-flow/reference/data#use-the-field-in-a-live-workflow

 

That said, I suspect that you are adding extra whitespace. Since you are using <br />, I would use hyphens on every tag, especially the name and address1

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.
amanda-91
Shopify Partner
84 0 48

 

I'll try adding some hyphens but the line breaks are attached to each bit of address data, with the fields in question having their break inside the conditional. 


These are all outputs from actual orders, by test I just mean I have an order setup not linked to a real customer and change the shipping address to see results when fulfilling the order (the flow output is an internal email sent, triggered by an order fulfillment). I can cancel fulfillment, change shipping address values, and fulfill again on this order when testing the flow results.

 

Both of those orders generating the output screenshots on my first post have NO values in the shipping address company, nor address2.... yet one of them has blank lines and the other doesn't based on this same code.  Stumped.

 

IMG_1569.jpeg

here are two orders' worth of inputs and their outputs. I don't understand why the Cletus order correctly omits the blank "company" and "address2" while the Joshua order adds blank lines. Neither order has values in these shipping address fields:

 

IMG_1579.jpeg

 

 

paul_n
Shopify Staff
1172 143 276

This is an accepted solution.

That second screen shot helps. I suspect your blank fields are coming through with spaces, so it passes the blank check and outputs an empty line. You could use something like:
{% assign my_address = fulfillmentOrder_item.destination.address2 | strip %}

{% if my_address != blank %}{{ my_address }}{% endif %}

 

Another way to do this would be to find and replace all spaces with something you can see (like "X"). That would help troubleshoot. 

 

If you are handy with code, you could also use the GraphiQL app to quickly write a query that gets this data. This is what I do when I suspect whitespace is causing a problem. In the API, it will return in quotes so you can sort of see the spaces. 

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.
amanda-91
Shopify Partner
84 0 48

Holy cow... that did it!!

 

I couldn't get the inspect filter to work, it kept kicking an error that it was expecting a different number of arguments, but the strip variables worked!

 

Still confused why things weren't working as-is, because when I'd output those liquid items into [brackets] they never contained spaces, so I guess something was getting lost in translation from Flow. No idea how I would've figured that out given the output never showed spaces when "blank"... but thanks so much!! This seemingly small glitch has had me aggravated for WEEKS!!