cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
defa07
New Member

Power Automate Substring weird behavior

Hy guys, hope you're doing fine 

 

For my first topic I have this "substring" error: 

 

The execution of template action 'Select' failed: The evaluation of 'query' action 'where' expression '{

  "sharepointItem": "@substring(item()['Task Name'], add(indexOf(item()['Task Name'], '-'), 2))"

}' failed: 'The template language function 'substring' parameter is out of range: 'start index' must be non-negative integer and should be less than the length of the string. Please see https://aka.ms/logicexpressions#substring for usage details.'.

 

I'm trying to execute this function as the key in a Select action, applied to a huge JSON content, and get a especific number after " - " symbol. For instance, from "Incidente - 15832", I would like to stick with the "15832". 

 

Flow setup:

 

 

What is quite confusing for me is when I grab the first item of JSON, for test purpose, and apply substring(first(body('Parse_JSON'))['Task Name'], add(indexOf(first(body('Parse_JSON'))['Task Name'], '-'), 2)), the formula works smoothly:

Issue_Compose.JPG 

 

I used lenght(item()['Task Name']) to check the lenght of strings and got the following values:

 

defa07_5-1610501001139.png

 

And indexOf(item()['Task Name'], '-') to know if each part of the formula returns the proper value:

 

Issue_Index.JPG

 

As well as just item()['Task Name']:

Issue_TaskItem.JPG

 

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @v-litu-msft,

 

Turns out it was a pagination issue on the "List rows in a table", where I set the threshold to 5000. For some reason, when I reduced it to 500, the flow worked!

 

Thanks for your support!!

View solution in original post

4 REPLIES 4
v-litu-msft
Community Support
Community Support

Hi @defa07,

 

It's so weird, your expression is collect and I tested on my side but not found the same issue:

Screenshot 2021-01-13 161546.jpg

 

How about using the split() function to do it: 

split(item()?['Task Name'],'- ')[1]

Screenshot 2021-01-13 161931.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Tks, @v-litu-msft ,

 

I'm afraid its a bug, beacause once more I tested your suggested formula on a Compose, and it returns the expected value, but in Select, now, I've just got the following error:

 

InvalidTemplate. The execution of template action 'Select' failed: The evaluation of 'query' action 'where' expression '{ "sharepointItem": "@split(item()?['Task Name'],'- ')[1]" }' failed: 'The template language expression 'split(item()?['Task Name'],'- ')[1]' cannot be evaluated because array index '1' is outside bounds (0, 0) of array. Please see https://aka.ms/logicexpressions for usage details.'.

 

Issue_WF_Split.JPG

v-litu-msft
Community Support
Community Support

Hi @defa07,

 

How about deleting the select action or recreating a new Flow to test it?

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-litu-msft,

 

Turns out it was a pagination issue on the "List rows in a table", where I set the threshold to 5000. For some reason, when I reduced it to 500, the flow worked!

 

Thanks for your support!!

View solution in original post

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Kudoed Authors
Users online (3,029)