Using IndexOf function in Power Automate

Power Automate is a powerful tool that can help admins and developers automate tasks and streamline workflows. One text function in power automate that can be used to help admins get a substring within a string of text is the indexOf function. In this blog we will be exploring this function and how you can utilize in a simple but effective manner.

First you must familiarize yourself with the indexOf function’s syntax as shown below:

indexOf('<text>', '<searchText>')

The results from the indexOf code are as follows:

The code will return a number greater or equal to zero if the search text is found in the text with ‘0’ being the first place of the text.

If the ‘search text’ is not found within the text it will return ‘-1’

Step-by-Step simple example in Power Automate

Step 1: Create A New instant cloud flow with a manual trigger.

Step 2: Add 2 parameters to your first action card as shown below:

Step 3: Add a compose action card to and use the following expression to utilize the indexOf function:

indexOf(triggerBody()['text'],triggerBody()['text_1'])

Step 4: Save and Test your flow. Use any text in the parameters to test your indexOf function. Remember if you get ‘-1’ as your output it will mean the text you are looking for cannot be found.

Spread the word

Leave a Reply