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

(if) Condition do nothing/ keep current value

Hello everyone,

 

there have already been some discussions on how to build an if condition that does nothing when false. However those Solutions do not seem to work for my case. Maybe you have some ideas to help me with this:

The request seems to be quite simple: If a certain colum(Actiontype) as a defined value do some calculations and put them into an other colum (Sum1). The Actiontype defines which sum colums (sum1-4) have to be updated. The sum colums already have some calculated values. 

I am using the Dataverse Connector but anyways I though this should work: Solved: do nothing in if function - Power Platform Community (microsoft.com) 

If eq(Actiontype),2, calculate and update sum1, do nothing

 

if(equals(triggerBody()['number']),2,variables('SummeEtat'))
if(equals(triggerBody()['number']),2,variables('SummeEtat'),)
if(equals(triggerBody()['number']),2,variables('SummeEtat'),'')

 

which either is not recognizes as a valid expression or promts this error:

 

Unable to process template language expressions in action 'Update_Controlling_Position_Etat_ANF_Prod' inputs at line '0' and column '0': 'The template language function 'equals' expects two parameters: the values to test for deep equality. The function was invoked with '1' parameter(s). Please see https://aka.ms/logicexpressions#equals for usage details.'.

 

 I have tried puting the current value of the field into the false condition but since the current value comes from one apply to each container and the if condition is in another apply to each container I get another error that the first apply to each has to be superior to the second one which is understandable. 

So maybe anyone has another idea on how to form an expression that updates a value if true and simply does nothing to the existing value if false. 

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
eliotcole
Super User
Super User

It is failing because your equals() functions are a little bit off, @TimFe, if you don't mind me saying.

 

This is what you currently have in that first if() statement, and I've fanned it out so you can see:

if(
  equals(
    triggerBody()['number']
  ),
  2,
  variables('SummeEtat')
)

What you have there is an equals statement without its second parameter. Your other two are similarly (but not the same) just a little off (I've fanned them in the below spoiler):

 

Spoiler
If #2 also has a bad equals, but the end of the if has an extra comma which infers more should be there:
if(
  equals(
    triggerBody()['number']
  ),
  2,
  variables('SummeEtat'),
)
If #3 is perhaps probably closest to what you're after, here, you wish it to be empty or null on the false branch.

It just still has the bad equals 😉:
if(
  equals(
    triggerBody()['number']
  ),
  2,
  variables('SummeEtat'),
  ''
)

So, using your 3rd if() as a basis, this would run correctly:

if(
  equals(
    triggerBody()['number'],
    2
  ),
  variables('SummeEtat'),
  ''
)

All that was done was moving that ',2' inside the equals(). Now it will check to see if triggerBody()['number'] is equal to 2 ... then it will pass the variable 'SummeEtat' if it is 2, and nothing if it isn't.

 

Plus, as @tom_riha, mentioned, you can also use null. Just make sure that the input you're entering null into is able to accept a null value. 👍 ... @tom_riha wrote:

Spoiler

Hello @TimFe,

I'd try two ideas:

1. use null value

if(equals(triggerBody()['number']),2,variables('SummeEtat'),null)

2. keep the original value

if(equals(triggerBody()['number']),2,variables('SummeEtat'),<the current value>)

e.g.

if(equals(triggerBody()['number']),2,variables('SummeEtat'),triggerBody()['number'])

 

View solution in original post

3 REPLIES 3
tom_riha
Super User
Super User

Hello @TimFe ,

I'd try two ideas:

1. use null value

if(equals(triggerBody()['number']),2,variables('SummeEtat'),null)

2. keep the original value

if(equals(triggerBody()['number']),2,variables('SummeEtat'),<the current value>)

e.g.
if(equals(triggerBody()['number']),2,variables('SummeEtat'),triggerBody()['number'])

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]
eliotcole
Super User
Super User

It is failing because your equals() functions are a little bit off, @TimFe, if you don't mind me saying.

 

This is what you currently have in that first if() statement, and I've fanned it out so you can see:

if(
  equals(
    triggerBody()['number']
  ),
  2,
  variables('SummeEtat')
)

What you have there is an equals statement without its second parameter. Your other two are similarly (but not the same) just a little off (I've fanned them in the below spoiler):

 

Spoiler
If #2 also has a bad equals, but the end of the if has an extra comma which infers more should be there:
if(
  equals(
    triggerBody()['number']
  ),
  2,
  variables('SummeEtat'),
)
If #3 is perhaps probably closest to what you're after, here, you wish it to be empty or null on the false branch.

It just still has the bad equals 😉:
if(
  equals(
    triggerBody()['number']
  ),
  2,
  variables('SummeEtat'),
  ''
)

So, using your 3rd if() as a basis, this would run correctly:

if(
  equals(
    triggerBody()['number'],
    2
  ),
  variables('SummeEtat'),
  ''
)

All that was done was moving that ',2' inside the equals(). Now it will check to see if triggerBody()['number'] is equal to 2 ... then it will pass the variable 'SummeEtat' if it is 2, and nothing if it isn't.

 

Plus, as @tom_riha, mentioned, you can also use null. Just make sure that the input you're entering null into is able to accept a null value. 👍 ... @tom_riha wrote:

Spoiler

Hello @TimFe,

I'd try two ideas:

1. use null value

if(equals(triggerBody()['number']),2,variables('SummeEtat'),null)

2. keep the original value

if(equals(triggerBody()['number']),2,variables('SummeEtat'),<the current value>)

e.g.

if(equals(triggerBody()['number']),2,variables('SummeEtat'),triggerBody()['number'])

 

mgr
Helper I
Helper I

I found out that the dataverse record is NOT going to be updated (so it's doing nothing) if for the "do nothing case" your formula delivers the same value that the trigger already delivered.

 

if(equals("do nothing","do nothing"),TriggerFieldContent,else...)

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (3,617)