Skip to main content

How to Use the if() Function in Power Automate

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Sometimes you don't need a whole Condition with two branches, just one value or another. if() does that inside an expression: give it something true or false, and the two values to choose between. This guide uses it to write a Boolean into a JSON body correctly.

What It Does​

Microsoft's functions reference says if() checks whether an expression is true or false and returns one of two values based on the result:

Syntax
if(<expression>, <valueIfTrue>, <valueIfFalse>)

Prerequisites​

  • Somewhere to use it: any field that takes an expression (How to Add an Expression). The example is the body of Update the list settings, a SharePoint REST request in the setup flow from Part 11 of the Career Development Plan series.

Example: A Boolean in a JSON Body​

Each list definition in the setup flow has a noCrawl value, false or true. The body sends it to SharePoint as NoCrawl, which hides a list from search when it's true.

Writing the value straight into the body with @{...} doesn't work. An expression inside text always becomes text, and a Boolean becomes False or True, with a capital letter, which isn't JSON. SharePoint answered Invalid JSON. A token was not recognized in the JSON content. (the fixes post shows the whole story).

if() writes the text yourself, in lowercase:

Expression
if(items('For_each_list')?['noCrawl'], 'true', 'false')

In the body, it goes where the value goes, without quotes around it:

Body (end)
"OnQuickLaunch": true,
"NoCrawl": @{if(items('For_each_list')?['noCrawl'], 'true', 'false')}
}

The designer shows the expression as an if(...) token:

The Update the list settings pane with four headers and a Body that ends with NoCrawl set to an if(...) expression token

For RoleCompetencies, noCrawl is false, so the body says "NoCrawl": false. For CompetencyResponses, it says "NoCrawl": true, and that list was hidden from search after the run.

The First Argument Is a Boolean​

The first value must be true or false. It can be a Boolean from your data, as here, or any expression that returns one:

Expression: a comparison
if(equals(items('For_each_list')?['title'], 'CompetencyResponses'), 'hidden', 'searchable')

if() or a Condition?​

UseWhen
if()You need one of two values in a field
ConditionYou need to run different steps (How to Add a Condition)

Common Mistakes​

MistakeWhat happensDo this instead
A Boolean straight into a JSON bodyIt arrives as True or FalseUse if(value, 'true', 'false')
Quotes around the @{...} in the bodyThe value is sent as a stringLeave it unquoted for a Boolean
Text as the first argumentThe expression failsPass a true-or-false value

Troubleshooting​

SymptomLikely causeFix
Invalid JSON from SharePointA Boolean became True or FalseWrap it in if()
Always the same resultThe first argument is never trueCheck what it returns in the run

FAQ​

Can I nest if()?​

Yes. The second or third value can be another if(), but past two levels a Condition or a Switch is easier to read.

Do the two values have to be text?​

No. They can be numbers, Booleans or anything else. Here they're text, because the body is text.

Conclusion​

if(test, valueIfTrue, valueIfFalse) picks one of two values inside an expression. In a JSON body, if(value, 'true', 'false') turns a Boolean into the lowercase true or false that JSON needs.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.