InsertData
→ numberAdds a new row to a Data Extension. Fails if a row with the same primary key already exists.
Available in:
Email
CloudPage
Automation
Triggered Send
Syntax
Platform.Function.InsertData(deName, fieldNames, fieldValues)
3 arguments
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
deName |
string | Yes | Data Extension name or external key |
fieldNames |
string[] | Yes | Array of column names to populate |
fieldValues |
array | Yes | Array of values aligned to fieldNames |
Description
InsertData adds a new row to a Data Extension. Returns the number of affected rows (1 on success).
If the DE has a primary key and a row with the same key already exists, InsertData will throw an error. Use UpsertData for insert-or-update behavior.
Examples
Basic insert
var rowsAffected = Platform.Function.InsertData(
"FormSubmissions",
["SubscriberKey","Email","Name","Timestamp"], [subscriberKey, email, name,Now()]
);
if (rowsAffected === 1) {
Write("Submission saved.");
}
Insert with error handling
try {
Platform.Function.InsertData(
"EventRegistrations",
["Email", "EventID", "Status"],
[email, eventId, "registered"]
);
} catch (e) {
// Duplicate primary key or other error
Write("Registration failed: " + e.message);
}
Insert from form data
Platform.Load("core", "1.1.5");
if (Platform.Request.Method === "POST") {
var email = Platform.Request.GetFormField("email");
var message = Platform.Request.GetFormField("message");
if (Platform.Function.IsEmailAddress(email)) {
Platform.Function.InsertData(
"ContactForm",
["Email", "Message", "CreatedAt"],
[email, message, Now()],
);
Platform.Response.Redirect("/thank-you", false);
}
}
Notes
InsertDataalways creates a new row — useUpsertDatato avoid duplicate errors- The
InsertDEfunction is an alias with identical behavior, however it is limited to emails. - Returns
1on success, throws on failure