Skip to main content
Question

Get last character of field and then set a value in another field based on the last character

  • August 7, 2026
  • 4 replies
  • 15 views

My Zap workflow reads a new WooCommerce Order and creates a new Xero invoice. I also have an Formatter step between those to add the shipping to the line items. Right now the Account Code for each line item is hard-coded. But I have two different kinds of items. If the sku ends with a D, then the account code for the invoice is 1000, but if it doesn’t end in a D then it is 2000. Shipping is fine left hard-coded.

I’m thinking I need another formatter step before the formatter than deals with the line items. I seems like the formatter would need to do this:

  1. extract the last character of the SKU (sku is a variable length)
  2. check if the last character is “D”
  3. conditionally set the account code to be refenced in the Xero step where the invoice is created

I could run a series of formatters like this:

  1. A text formatter to get the length of the SKU
  2. Another text formatter to truncate the sku [ return 1 character, skip length from step 1 above minus 1)
  3. Another formatter of some kind to assign the value of the Account Code depending on step 2 above results

That seems like a lot of separate steps. What would be the best/most efficient approach to finding the last character and then running a conditional on it?

4 replies

  • Author
  • Beginner
  • August 7, 2026

I did a little searching around on how to do this and using the Code By Zapier accomplished checking the last digit of the SKU and returning the Account Code with just a few lines of JavaScript.


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • August 7, 2026

Hi ​@EllieHPC 

Most efficient is to use a Code step.

Help: https://zapier.com/apps/code/integrations#help

 

You can try using an AI step: https://zapier.com/apps/ai/integrations#help

 

Code steps use 1+ Tasks.

AI steps use 1+ Tasks.

Formatter steps use 0 Tasks.

 

Formatter steps can handle line items.

Help: https://zapier.com/apps/formatter/integrations#help

 

Try these Formatter steps:

  • Formatter > Text > Extract Pattern
    • Pattern: .$
      • This gets the last character
  • Formatter > Utilities > Lookup Table

  • Author
  • Beginner
  • August 7, 2026

Yup. Used a Code step. Pretty easy if you know a little Javascript (luckily, I do!)


SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • August 12, 2026

Hi ​@EllieHPC 👋 Glad you got it working with a Code step!

Would you be up for sharing the code you used here? Could be really helpful for anyone else who wants to use the same approach. 🙏