Platform.Function.UpdateData()

Updates data in a data extension and returns the number of rows updated.

You can use this function in CloudPages, landing pages, microsites, and SMS messages in MobileConnect. To update rows in a data extension in an email, use the Platform.Function.UpdateDE() function.

Syntax

Platform.Function.UpdateData(1, 2, 3, 4, 5)

Properties

Ordinal Type Description
1 String Required. The name of the data extension that contains the data to update.
2 Array Required. An array that contains the column names to search for a matching value.
3 Array An array that contains values to filter on.
4 Array Required. An array that contains that names of the columns to update.
5 Array Required. An array that contains the new values for the specified columns.

Usage

To use the function, first pass it the name of the data extension that contains the data you want to update. Next, pass it an array of the columns to search to find the row that you want to update and optionally an array that includes the values that identify the row to update. Finally, pass it an array that contains the names of the columns that you want to update the data in, and an array that contains the updated values for those columns.

Updating a Single Value

In this example, a data extension called "Flights" contains the data in this table.

FlightId Origin Dest Price PerBagSurcharge
1 IND NYC 100
2 IND LAX 200
3 IND SEA 500 25
4 ORD SEA 525 10
5 ORD LAX 400
6 SEA SAN 300
7 SEA ATL 10
8 ATL AUS 350 10
9 STL KCA 5
10 IND ATL 125

To update the Price value for FlightId 10, use this function.

<script runat="server">
  Platform.Load("core", "1");
  try {
    var result = Platform.Function.UpdateData("Flights",
                                              ["FlightId"],
                                              [10],
                                              ["Price"],
                                              ["316"]);
    Write(Stringify(result));
  } catch(e) {
    Write(Stringify(e));
  };
</script>

The function returns 1, indicating that it updated one row. The data extension now contains this data.

FlightId Origin Dest Price PerBagSurcharge
1 IND NYC 100
2 IND LAX 200
3 IND SEA 500 25
4 ORD SEA 525 10
5 ORD LAX 400
6 SEA SAN 300
7 SEA ATL 10
8 ATL AUS 350 10
9 STL KCA 5
10 IND ATL 316

Updating Multiple Values in One Row

You can use the Platform.Function.UpdateData() function to update more than one column in a single row in one operation. To update multiple columns, you must provide one set of search criteria for each column that you want to update.

This example uses a data extension called "Flights2" that contains the data in this table.

FlightId Origin Dest Price PerBagSurcharge
1 IND NYC 100
2 IND LAX 200
3 IND SEA 500 25

Use this code to update the Dest, Price, and PerBagSurcharge fields for FlightId 1.

<script runat="server">
  Platform.Load("core", "1");
  try {
    var result = Platform.Function.UpdateData("Flights2",
                                              ["FlightId","Origin","Dest"],
                                              [1, "IND", "NYC"],
                                              ["Dest", "Price", "PerBagSurcharge"],
                                              ["JFK", 75, 10]);
    Write(Stringify(result));
  } catch(e) {
    Write(Stringify(e));
  };
</script>

The function returns 1, indicating that it updated one row. The data extension now contains this data.

FlightId Origin Dest Price PerBagSurcharge
1 IND JFK 75 10
2 IND LAX 200
3 IND SEA 500 25