cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
livingstonep
Level 8

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
Super User
Super User

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



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

Proud to be a Flownaut!


View solution in original post

1 REPLY 1
Super User
Super User

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



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

Proud to be a Flownaut!


View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 293 members 5,258 guests
Please welcome our newest community members: