cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
OlafStetzer
Level: Powered On

trim function not working on empty string

Hello,

 

I am using (or trying to use) the trim function in combination with the result of an approval,
specifically the comment. Now it seems that the function throws an error when there is no comment, e.g.
the function has to operate on an empty string. Is there a good workaround for this?

This is my current code:

if(equals(length(trim(body('Aktualisiertes_Approval_aus_Logliste_abrufen')?['Approver_Kommentar'])),0),'',concat('_',trim(body('Aktualisiertes_Approval_aus_Logliste_abrufen')?['Approver_Kommentar']),'_'))

The purpose of the function is to add the comment to a string with markup: _approver comment_

But since this does not work with empty strings, the _ _ shall be omitted in this case.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: trim function not working on empty string

Hi @OlafStetzer ,

 

Do you want to concat the approval comments with other characters if it is not empty?

 

Please consider using an empty function to check if the comment is empty or not, then combine with other characters depends on situation.

 

I have configured the flow likes below for your reference:

if(empty(items('Apply_to_each')?['comments']),'',concat('_',trim(items('Apply_to_each')?['comments']),'_'))

1.PNG

 

Best regards,

Mabel

 

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

View solution in original post

3 REPLIES 3
Dual Super User
Dual Super User

Re: trim function not working on empty string

I know its going to legthen the function, but I suspect you are going to need to enclose this (or parts of it) inside an If(isblank(body('Aktualisiertes_Approval_aus_Logliste_abrufen')?['Approver_Kommentar']),true function, false function) to test for a blank comment before processing the Trim.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Community Support Team
Community Support Team

Re: trim function not working on empty string

Hi @OlafStetzer ,

 

Do you want to concat the approval comments with other characters if it is not empty?

 

Please consider using an empty function to check if the comment is empty or not, then combine with other characters depends on situation.

 

I have configured the flow likes below for your reference:

if(empty(items('Apply_to_each')?['comments']),'',concat('_',trim(items('Apply_to_each')?['comments']),'_'))

1.PNG

 

Best regards,

Mabel

 

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

View solution in original post

OlafStetzer
Level: Powered On

Re: trim function not working on empty string

Thank you. It is in fact not the isblank function (this does not exist) but the empty function.

 

Yes the function gets really lng this way nad the little editor window for functions does not make it easy to edit long functions either. But it works now.

 

What I do not understand: Why is Micrsoft not able to programm this and other functions in a way that they are more robust. E.g. a string function should still work on empty strings, just do nothing. Flow is considered as a end user programming environment so end users should not be bothered with exceptions handling where it can be avoided.

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 (Last 30 Days)
Users online (6,978)