Need Flow help: Customer & Order information title cased

I created a Flow to adjust the case of the customer and shipping information so that it is all in title case. Some customers do all caps, some all lower, and there are some in between, but I’d like it to be uniform. I followed another post’s instructions and even had Sidekick assist.

My process is: (see pics for examples)

  1. orderUpdate: downcase
  2. orderUpdate: capitalize
  3. customerUpdate: downcase
  4. customerUpdate: capitalize

I have tried to run this manually on existing orders, however I have gotten this error:

Exception: Mutation had user errors: “Enter a last name”, “Select a country/region”, “Enter an address”, “Enter a postal code”, “Enter a city”, “Enter a phone number”

TIA!

Pretty sure you need all fields. From my understanding, the address update isn’t a partial. It needs everything. Also country code should be v2.

{

  "input": {

    "id": "{{ order.id }}",

    "shippingAddress": {

      "address1": "{{ order.shippingAddress.address1 | downcase }}",

      "address2": "{{ order.shippingAddress.address2 | downcase }}",

      "city": "{{ order.shippingAddress.city | downcase }}",

      "company": "{{ order.shippingAddress.company | downcase }}",

      "firstName": "{{ order.shippingAddress.firstName | downcase }}",

      "lastName": "{{ order.shippingAddress.lastName | downcase }}",

      "phone": "{{ order.shippingAddress.phone }}",

      "zip": "{{ order.shippingAddress.zip }}",

      "countryCode": "{{ order.shippingAddress.countryCodeV2 }}"

    }

  }

}
2 Likes

With your update, I now get this: Exception: Mutation had errors: “Variable $input of type OrderInput! was provided invalid value for shippingAddress.countryCode (Expected “” to be one of: AF, AX, AL, DZ, AD, AO, AI, AG, AR, AM, AW, AC, AU, AT, AZ, BS, BH, BD, BB, BY, BE, BZ, BJ, BM, BT, BO, BA, BW, BV, BR, IO, BN, BG, BF, BI, KH, CA, CV, BQ, KY, CF, TD, CL, CN, CX, CC, CO, KM, CG, CD, CK, CR, HR, CU, CW, CY, CZ, CI, DK, DJ, DM, DO, EC, EG, SV, GQ, ER, EE, SZ, ET, FK, FO, FJ, FI, FR, GF, PF, TF, GA, GM, GE, DE, GH, GI, GR, GL, GD, GP, GT, GG, GN, GW, GY, HT, HM, VA, HN, HK, HU, IS, IN, ID, IR, IQ, IE, IM, IL, IT, JM, JP, JE, JO, KZ, KE, KI, KP, XK, KW, KG, LA, LV, LB, LS, LR, LY, LI, LT, LU, MO, MG, MW, MY, MV, ML, MT, MQ, MR, MU, YT, MX, MD, MC, MN, ME, MS, MA, MZ, MM, NA, NR, NP, NL, AN, NC, NZ, NI, NE, NG, NU, NF, MK, NO, OM, PK, PS, PA, PG, PY, PE, PH, PN, PL, PT, QA, CM, RE, RO, RU, RW, BL, SH, KN, LC, MF, PM, WS, SM, ST, SA, SN, RS, SC, SL, SG, SX, SK, SI, SB, SO, ZA, GS, KR, SS, ES, LK, VC, SD, SR, SJ, SE, CH, SY, TW, TJ, TZ, TH, TL, TG, TK, TO, TT, TA, TN, TR, TM, TC, TV, UG, UA, AE, GB, US, UM, UY, UZ, VU, VE, VN, VG, WF, EH, YE, ZM, ZW, ZZ)”

Add a condition step before all these order updates

order.shippingAddress.lastName is not blank

AND order.shippingAddress.countryCode is not blank

AND order.shippingAddress.address1 is not blank

AND order.shippingAddress.zip is not blank

AND order.shippingAddress.city is not blank

AND order.shippingAddress.phone is not blank


1 Like

Just so you know, not all orders are going to have the country code… and the country code is required to update the shipping address here.

The problem is order.customer.defaultAddress is not selected in the orderUpdate mutation’s response, so it uses empty strings which are invalid.

Does Flow let you select the field to return from a mutation response? I don’t think it does.

I’d start by finding why all entry fields here are empty except for order id:

Have you typed variables manually or selected from the picker?

There seems to be no screenshot for the action which produces this error –
Error output mentions shippingAddress while action screenshots are updates for defaultAddress.

Keep in mind that when you place an order you specify order shipping address, however customer may have no address at all.
And if it has, it may have several and a non-default address may be used.

In addition, I’d recommend instead of

 "address1": "{{ order.shippingAddress.address1 | downcase }}",

do

 "address1": {{ order.shippingAddress.address1 | downcase | json }},

as this will do better escaping.

1 Like

Okay, I tried stripping it down to just the one step for now but it’s still giving issues. I did add in Billing Address as well, but the error kicks even without it.

1 Like

The exception is different the JSON your outputting is malformed not that it’s missing; though it may be missing but one at a time.

The countryCode , line 13, is missing a comma at the end.

2 Likes

Also, when you get to the customer update step, I’m not 100 on this because I don’t know a lot here, but I think it’s supposed to be “addresses” not “defaultAddress”.

When you use json filter you do not wrap the output in double quotes (refer to my example code above ) – this is the reason for “invalid JSON” error.

And line 13, of course, too.