Substring Left Right Expression

MVP

Hello All,

 

I've built an expression in Power Automate and want to know if there is a better way to achieve the same result. The expression creates a work order number that concatenates a prefix value, leading zeros and a unique number. The leading zeros and unique number should not exceed 5 characters in length.

 

Here is an example work order number: "ES00099"

 

As far as I know there is no "Left" or "Right" style functions in Power Automate to simplify this expression.

 

In my expression I am:

  1. Concatenating "00000" and the List ID number ("99"). Results in "0000099".
  2. Determine concatenated string length (7); Subtract it from the desired string length (5) = 3.
  3. Substring "0000099" and using Step #2 result (3) and desired string length (5). Results in "00099".
  4. Concatenate "AA" to Step #3 result. Results in "ES00099".

clipboard_image_0.png

 

Here is the full expression code:

concat('ES', substring(concat('00000', triggerBody()?['ID']), sub(length(concat('00000', triggerBody()?['ID'])), 5), 5))

 

The code works but I'm thinking there must be a more elegant way.

 

Thanks.

 

Norm

 

1 Reply

Hi @Norman Young,

 

try this expression:

concat('ES', formatNumber(triggerBody()?['ID'], '00000'))