Forum Discussion

Norman Young's avatar
Jan 11, 2020

Substring Left Right Expression

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".

 

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

 

Resources