Skip to main content

How to Check Whether an Array Contains a Value with contains() in Power Automate

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Before a flow removes something, it should check that it's there. contains() answers that: does this array include this value? This guide uses it to check whether a SharePoint view shows a column before a step removes the column from it.

What It Does​

Microsoft's functions reference says contains() checks whether a collection has a specific item, and returns true or false. It works on three kinds of collection:

CollectionIt looks for
TextA piece of the text
An arrayA value
An objectA property name

The reference also notes that the check is case-sensitive.

Prerequisites​

  • An array to search. The example comes from the setup flow in Part 11 of the Career Development Plan series. Find Title in the view asks SharePoint for a list's default view columns, and its body has them in Items (How to Use the body() Function):
Body of Find Title in the view, once Title is out of the view
{
"SchemaXml": "<FieldRef Name=\"Competency\" /><FieldRef Name=\"JobTitle\" /><FieldRef Name=\"Level\" /><FieldRef Name=\"IsActive\" />",
"Items": ["Competency", "JobTitle", "Level", "IsActive"]
}

On a new list, Items is ["LinkTitle"]: LinkTitle is the Title column as a view shows it.

Write the Expression​

Expression
contains(body('Find_Title_in_the_view')?['Items'], 'LinkTitle')

It's true when the view shows Title, and false otherwise.

Use It in a Condition​

Add a Condition (How to Add a Condition), put the expression in its first value, choose is equal to, and add true as an expression in the second:

The If Title is in the view pane with contains(...) is equal to true, both expression tokens

The step that removes the column goes in the True branch:

The flow with Find Title in the view, then If Title is in the view with Remove Title from the view in its True branch, then For each column

Check Both Branches​

  • False: on lists whose view no longer had Title, the run skipped the removal.
  • True: I put Title back in one list's view with SharePoint's Show or hide columns, and ran the flow again. Items included LinkTitle, the removal ran, and Title was out of the view afterwards.

Without this check, removing a column that isn't in the view fails, and Power Automate spends minutes retrying it (Fixed: "Invalid Field Name" BadGateway).

Common Mistakes​

MistakeWhat happensDo this instead
The wrong case'linktitle' doesn't match LinkTitleCopy the value exactly
Searching an array of objects for a property valueIt compares whole items, not their propertiesSearch an array of plain values, such as Items
Comparing with true typed as textThe condition may never be trueAdd true as an expression

Troubleshooting​

SymptomLikely causeFix
Always falseThe value or its case differsRead the array in the run's outputs
An error about the arrayThe property isn't in the bodyCheck the body's shape in a run

FAQ​

Can contains() search text?​

Yes. With text, it checks whether one piece of text is inside the other, such as contains('Career Development Plan', 'Plan').

How do I check whether any item has a certain property value?​

Microsoft's expression cookbook suggests Filter array, then checking the length of the result, because contains() on an array of objects compares whole objects.

Conclusion​

contains(array, 'value') is true when the array includes the value, matching case exactly. Put it in a Condition before any step that removes or changes something, so the step runs only when there's something to act on.

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.