How to Replace Value in an Array in Power Automate

Recently, I have worked with the Leave Approval Process system, which enables employees to submit their requests through Microsoft Forms, and the responses are stored in a SharePoint list. Microsoft Forms has an Email field, where I need to save emails to a SharePoint list.

Here, I faced an Issue: The data is coming in an Array of Emails ending with a semicolon(;). To store the values in a SharePoint list, I need to separate the emails with commas.

This can be achieved by using the replace() function in Power Automate.

In this tutorial, I will explain how to replace value in an array using Power Automate with the following examples.

  • Replace a string in an Array in Power Automate
  • Replace Object in Array in Power Automate
  • Replace Special Characters in an Array in Power Automate

Replace String in an Array using Power Automate

Suppose, let’s take an array like this. In the below array value, I wanted to replace a String value from ‘Power Apps‘ to ‘Power BI‘.

[
  {
    "Category": "Connector",
    "Value": "SharePoint"
  },
  {
    "Category": "Tool",
    "Value": "Power Automate"
  },
  {
    "Category": "Tool",
    "Value": "Power Apps"
  }
]

Do follow the steps below to replace a string value in Array Power Automate:

  1. Browse make.powerautomate.com to open the Power Automate Home page. Create an Instant cloud flow that can be triggered manually with a single button click.
  2. Then, add an “Initialize variable” action and set the variable’s name, type as Array, and value to empty.
Replace string in Array Power Automate
  1. Next to that, add a “Compose” action with the array values as shown in the screenshot below.
Power Automate replace string in array
  1. Then, add an Apply to each loop action and select an output from previous steps to: Choose Compose Outputs.
Power Automate replace string from array
  1. Inside the loop, add “Append to array variable” action and select Name of Array variable from the previous action and Value as below.
{
  "Category": "@{item()?['Category']}",
  "Value": "@{replace(item()?['Value'],'Power Apps','Power BI')}"
}
power automate replace value in array
  1. To display the replaced string, take a “Compose” action. Provide input parameters with Initialize variable [Power Platform].
Replace item in array Power Automate

Click the Save button to save the flow and run it manually. When the flow runs successfully, you can see the result in the Compose action outputs.

Output:

Replace value in array Power Automate

This is how you can replace a string from an array using Power Automate.

Check out Create an Array From SharePoint List Items Using Power Automate

Replace Object Value from an Array using Power Automate

Now, we will see how to replace multiple object values in an array using Power Automate.

Below, I will work with an array containing multiple objects, as shown in the code below. In the given array, I want to replace the Status of objects whose value is ‘Pending’ with the value ‘In Progress’.

[
  {
    "TaskID": "T001",
    "TaskName": "Create Power Platform PDF",
    "Status": "Pending"
  },
  {
    "TaskID": "T002",
    "TaskName": "Develop Site Page",
    "Status": "Pending"
  },
  {
    "TaskID": "T003",
    "TaskName": "Create a Web Part",
    "Status": "In Progress"
  },
  {
    "TaskID": "T003",
    "TaskName": "Create a Site Page",
    "Status": "Completed"
  }
]

Here, I will create an Instant cloud flow in Power Automate.

See the steps below:

  1. Into the Power Automate flow, add an “Initialize variable” action. Provide name, type as Array, and value with multiple array objects as below.
Power Automate replace Object in array
  1. Now, add “Select” flow action, and set the required parameters as below.
    • From: Take the initialized variable output from the previous step.
    • Map: Follow the table below
KeyValue
TaskIDitem()?[‘TaskID’]
TaskNameitem()?[‘TaskName’]
Statusif(equals(item()?[‘Status’],’Pending’),replace(item()?[‘Status’],’Pending’,’In Progress’),item()?[‘Status’])
Replace Object in array Power Automate
  1. Then, add a “Set variable” action to see the replaced item values. Provide the parameters.
    • Name: Select the Array variable from the drop-down options.
    • Value: Choose the output of the Select action from the dynamic content.
Replace Object from array in Power Automate
  1. Once the flow is ready, click the Save button to save the flow. Then, run the flow manually. The result can be seen in Set variable outputs.

Output:

Replace object item in array Power Automate

Check out How to Initialize Object Variable in Power Automate

Replace Special Character in Array using Power Automate

Suppose we consider an Array of Emails, as shown in the code below. From the below array, I’d like to replace the semicolon (;) with a blank at the end of the email addresses.

[
  {
    "Email": "[email protected];"
  },
  {
    "Email": "[email protected];"
  },
  {
    "Email": "[email protected];"
  }
]

By following the above examples, you already know how to create a flow in Power Automate. Let’s start with the following steps.

  1. After that, add an “Initialize variable” action with empty array values. Provide name, type as Array, and value for an array variable.
Power Automate character in array
  1. Now, add a “Compose” action to store the Array of Email addresses in the Inputs parameter.
Power Automate character in an array
  1. Then, add “Apply to each loop” by taking the outputs of the Compose action into it.
Power Automate replace special characters in array
  1. Inside the loop, take the “Append to array variable” action, where we will append the email address by replacing the semicolon with a blank value. Set the parameters below.
    • Name: Choose an initialized variable array from the drop-down.
    • Value: Insert the code below.
replace(item()?['Email'],';','')
Replace special characters in array Power Automate
  1. To see the output, add one more Compose action and set the Input parameter.
    • Inputs: Provide an initialized variable from the previous step.
Replace character value in array Power Automate

Now the flow is ready, save and run it.

Output:

Power Automate Replace characters in Array

You can use the replace() function in Power Automate to replace a value in an array. Here, I have explained three different examples of replacing values in an array using Power Automate. Do let me know if you still have any questions in the comments section.

You may like the following tutorials:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…