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

  • InsertData always creates a new row — use UpsertData to avoid duplicate errors
  • The InsertDE function is an alias with identical behavior, however it is limited to emails.
  • Returns 1 on success, throws on failure

See Also