cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jdaniels
Frequent Visitor

Contains or Ends With condition previously worked, now doesn't

I have a condition that checks if an equal sign is present in the comments field from a sharepoint list item. The condition is shown below:

flow-shot.png

I have tried it with and without the string expression (plain "="). I've tried the contains and ends with conditions, and tried to create a longer expression like many of the answers suggest. Although with the longer expression, they are using advanced options in the condition, of which I don't see.

This is the error that I am getting:

flow-error.png

Any ideas of how to best approach this so it runs consistently?

 

Thanks,

 

Jim 

1 ACCEPTED SOLUTION

Accepted Solutions
eliotcole
Responsive Resident
Responsive Resident

There are a few ways to get the equals sign to be recognised, but by far the easiest is to initialise a string variable with the value:

 

=

 

 

That should be then usable in your condition.

 

-----

 

Solution

So firstly, here's the solution for your current flow, where I realised that a string variable can accept a null input, so this flow will work:

fullyworking.jpg

 

I've defined a commentVAR string variable in there. That will accept null entries from the SharePoint list, then you can run the Condition based upon that and the equalsVAR string variable.

 

That is using your original flow structure, I think. I'm sure this will work with any OR structure that you decide upon, too.

 

-----

 

Alternative Solution

If it were me, I would go a slightly different way ... I would have a variable with decides which branch of a switch to use, and that would be your condition written out in an expression like so:

 

 

 

 

if(
    endsWith(variables('commentVAR'), variables('equalsVAR')), 
	'endItAllPlease', 
	if(
	    contains(variables('commentVAR'), variables('equalsVAR')), 
		'equalityIsHere', 
		'nothingIsEqual')
)

 

 

 

Remember that must all be a single string, the above is to understand the logic, here is the single string:

 

 

if(endsWith(variables('commentVAR'), variables('equalsVAR')), 'endItAllPlease', if(contains(variables('commentVAR'), variables('equalsVAR')), 'equalityIsHere', 'nothingIsEqual'))

 

 

 

Here's the new part of the flow:

how i would do it.jpg

 

Here is the flow with an extra branch to provide a specific action on no comment:

no comment!no comment!

 

And that code with the null (empty) value as the first level:

 

 

if(
	equals(variables('commentVAR'), ''), 
	'noReplyAtAll', 
	if(
		endsWith(variables('commentVAR'), variables('equalsVAR')), 
		'endItAllPlease', 
		if(
			contains(variables('commentVAR'), variables('equalsVAR')), 
			'equalityIsHere', 
			'nothingIsEqual'
			)
		)
	)

 

 

Here it is as one string:

 

 

if(equals(variables('commentVAR'), ''), 'noReplyAtAll', if(endsWith(variables('commentVAR'), variables('equalsVAR')), 'endItAllPlease', if(contains(variables('commentVAR'), variables('equalsVAR')), 'equalityIsHere', 'nothingIsEqual')))

 

 

You can add an extra level of if/then if you'd like to account for entries without a comment, just do the equals=null thing on the final rung, and add an extra switch item. (I will edit in that version)

View solution in original post

5 REPLIES 5
CFernandes
Super User III
Super User III

Hello @jdaniels 

 

It seems you SP fieild Comment was empty(null) and that is why the condition failed.

 

You can use your condition and add another condition OR Comment isnotequal to null.  

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

 

@CFernandes , there will be submissions that have comments entered but do not have an '=' in the comments. It needs to only trigger when the comments have an '=' in them. Will the additional 'OR' comment support this?

eliotcole
Responsive Resident
Responsive Resident

There are a few ways to get the equals sign to be recognised, but by far the easiest is to initialise a string variable with the value:

 

=

 

 

That should be then usable in your condition.

 

-----

 

Solution

So firstly, here's the solution for your current flow, where I realised that a string variable can accept a null input, so this flow will work:

fullyworking.jpg

 

I've defined a commentVAR string variable in there. That will accept null entries from the SharePoint list, then you can run the Condition based upon that and the equalsVAR string variable.

 

That is using your original flow structure, I think. I'm sure this will work with any OR structure that you decide upon, too.

 

-----

 

Alternative Solution

If it were me, I would go a slightly different way ... I would have a variable with decides which branch of a switch to use, and that would be your condition written out in an expression like so:

 

 

 

 

if(
    endsWith(variables('commentVAR'), variables('equalsVAR')), 
	'endItAllPlease', 
	if(
	    contains(variables('commentVAR'), variables('equalsVAR')), 
		'equalityIsHere', 
		'nothingIsEqual')
)

 

 

 

Remember that must all be a single string, the above is to understand the logic, here is the single string:

 

 

if(endsWith(variables('commentVAR'), variables('equalsVAR')), 'endItAllPlease', if(contains(variables('commentVAR'), variables('equalsVAR')), 'equalityIsHere', 'nothingIsEqual'))

 

 

 

Here's the new part of the flow:

how i would do it.jpg

 

Here is the flow with an extra branch to provide a specific action on no comment:

no comment!no comment!

 

And that code with the null (empty) value as the first level:

 

 

if(
	equals(variables('commentVAR'), ''), 
	'noReplyAtAll', 
	if(
		endsWith(variables('commentVAR'), variables('equalsVAR')), 
		'endItAllPlease', 
		if(
			contains(variables('commentVAR'), variables('equalsVAR')), 
			'equalityIsHere', 
			'nothingIsEqual'
			)
		)
	)

 

 

Here it is as one string:

 

 

if(equals(variables('commentVAR'), ''), 'noReplyAtAll', if(endsWith(variables('commentVAR'), variables('equalsVAR')), 'endItAllPlease', if(contains(variables('commentVAR'), variables('equalsVAR')), 'equalityIsHere', 'nothingIsEqual')))

 

 

You can add an extra level of if/then if you'd like to account for entries without a comment, just do the equals=null thing on the final rung, and add an extra switch item. (I will edit in that version)

View solution in original post

jdaniels
Frequent Visitor

@eliotcole thank you for the detailed explanation. The first reference worked flawlessly. Now that I have it working, I'm going to create a copy and try to use your recommended method.

Jim

eliotcole
Responsive Resident
Responsive Resident

Nice, cheers, @jdaniels ! Much obliged. 😀

 

Don't fret if it doesn't kick in straight away, just recheck your variable names and if/then result strings ( which I'm sure you'll change 😅 ) as that is usually where my flows mess up. Also, let's be real, we're using flow to get *away* from complicated bundles of text, so that the infrastructure of what it does is usuable by others in the future.

 

Another thing I do ( hence those 'logical views' of the expressions ) is to copy a long expression over to a notepad++ and open it up with tabs and new lines. That way I can ( usually ) have a bit of help in differentiating the various parts involved, as Power Automate isn't always a great place to edit expressions. 😉


@jdaniels wrote:

@eliotcole thank you for the detailed explanation. The first reference worked flawlessly. Now that I have it working, I'm going to create a copy and try to use your recommended method.

Jim


EDIT - Oh yeah! Remember you don't HAVE to use that long expression to decide the path, you could just use your existing full flow conditions to 'Set equalJusticeVAR' with. 👍

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

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Users online (19,062)