cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Kudo Collector
Kudo Collector

MS Flow "right" string function - get rightmost 6 characters of a string

We are trying to do this in our Flow:

 

concat(items('Apply_to_each_BHF_Red_Tote')['T_x002d_Code'],
'-',
right(concat('00000',items('Apply_to_each_BHF_Red_Tote')['BoxNo']),5),
'-',
right(concat('000000',items('Apply_to_each_BHF_Red_Tote')['ID'])),6)

but Right function is not recognized...

I also tried:

substring(concat('000000', variables('ItemID'))
, sub(6, length(variables('ItemID')))
, add(6, length(variables('ItemID'))))

but no luck - I get an error:

template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Integer'

 

the thing is the BoxNo will increment up to 99,999, and the ID of the record can go up to 999,999

 

so how can we concat the leading zeros and return only the 5 rightmost characters?

so how can we do that please

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
MVP

Re: MS Flow "right" string function - get rightmost 6 characters of a string

Hi @livingstonep,

 

I think you are almost there... I understand you to mean that you wish the result to be a text value with leading zeroes padding the number to make it 6 characters long - is that correct?

The reason for the error about the length function is because the BoxNo is a number, but the length function only works on strings (or collections, which can be "collections" of characters in a text string). So first BoxNo must be converted to text using the string function. In my testing, I first used a Compose action which I named BoxNoString to do the concatenation as you suggested, to add leading zeroes:

concat('000000',string(body('Get_item')?['BoxNo']))

I did this just for ease of referring to it twice in the next Compose action, which gets the rightmost 6 characters:

skip(outputs('BoxNoString'),sub(length(outputs('BoxNoString')),6))

What the above expression does is subtract 6 from the length of the first Compose output (BoxNoString), and uses that as the index for the skip function to skip to. Similar to length, skip is listed under Collection functions, but it also works on a collection/array of characters.

So, for example, if the input is 99, the BoxNoString Compose outputs 00000099, and then the second Compose subtracts 6 from 8, and then skip returns all the characters beginning at that index (2, which is the 3rd character), giving a result of 000099.

Does this work for you...?

Sandy
@SandyU



Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!


View solution in original post

1 REPLY 1
Highlighted
MVP

Re: MS Flow "right" string function - get rightmost 6 characters of a string

Hi @livingstonep,

 

I think you are almost there... I understand you to mean that you wish the result to be a text value with leading zeroes padding the number to make it 6 characters long - is that correct?

The reason for the error about the length function is because the BoxNo is a number, but the length function only works on strings (or collections, which can be "collections" of characters in a text string). So first BoxNo must be converted to text using the string function. In my testing, I first used a Compose action which I named BoxNoString to do the concatenation as you suggested, to add leading zeroes:

concat('000000',string(body('Get_item')?['BoxNo']))

I did this just for ease of referring to it twice in the next Compose action, which gets the rightmost 6 characters:

skip(outputs('BoxNoString'),sub(length(outputs('BoxNoString')),6))

What the above expression does is subtract 6 from the length of the first Compose output (BoxNoString), and uses that as the index for the skip function to skip to. Similar to length, skip is listed under Collection functions, but it also works on a collection/array of characters.

So, for example, if the input is 99, the BoxNoString Compose outputs 00000099, and then the second Compose subtracts 6 from 8, and then skip returns all the characters beginning at that index (2, which is the 3rd character), giving a result of 000099.

Does this work for you...?

Sandy
@SandyU



Did I answer your question? Mark my post as a solution!

Proud to be a Flownaut!


View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (6,956)