cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MattMcQ
Helper I
Helper I

How to use substring without knowing string length

I have a flow that reads a SharePoint list and converts that into a CSV table with custom columns. I was trying to take one of the columns and use the substring() function on it to only take the first 90 characters like this: 

Substring(@item()?['Justification_x0020_for_x0020_Sp'],0,90)

. However this throws an error when the field is empty or less than 90 characters long. I was going to try and manage this AFTER the CSV table was created but the field is rich text and can contain line feeds so I can't do a split for each row and then  try to process each column. 

 

Is there a way to just pull the first X characters of a field in the CSV table step without the substring() function?

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

You could do this:

if
(
  greater(length(outputs('Justification')), 90),
  substring(outputs('Justification'), 0, 90),
  outputs('Justification')
)

You will need to replace outputs('Justification') with your value. 

This checks to see if the string is greater than 90 characters, if it is, it gets the first 90 characters. If it is less than 90, it just outputs the value.

 

Make sense?

View solution in original post

2 REPLIES 2
Paulie78
Super User
Super User

You could do this:

if
(
  greater(length(outputs('Justification')), 90),
  substring(outputs('Justification'), 0, 90),
  outputs('Justification')
)

You will need to replace outputs('Justification') with your value. 

This checks to see if the string is greater than 90 characters, if it is, it gets the first 90 characters. If it is less than 90, it just outputs the value.

 

Make sense?

MattMcQ
Helper I
Helper I

I thought I tried that and it didn't work, but I wasn't using greater(). It does work now though. Thank you.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (3,132)