Lookup a Data Extension record verified

Learn how to lookup Data Extension records (rows) in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include Core and Platform methods.

Platform

Retrieve a single row using a single parameter

var name = "MyDataExtension";

var result = Platform.Function.Lookup(
    name,
    "FirstName",
    "EmailAddress",
    "example@mail.com"
);
<script runat="server">
	try {

        var name = "MyDataExtension";

        var result = Platform.Function.Lookup(
            name,
            "FirstName",
            "EmailAddress",
            "example@mail.com"
        );

        Platform.Response.Write(Platform.Function.Stringify(result));
		
	} catch(error) {
        Platform.Response.Write(Platform.Function.Stringify(error));
    }
</script>
"John"

Retrieve multiple rows using a single parameter

var name = "MyDataExtension";

var result = Platform.Function.LookupRows(
    name,
    "EmailAddress",
    "example@mail.com"
);
<script runat="server">
	try {

        var name = "MyDataExtension";

        var result = Platform.Function.LookupRows(
            name,
            "EmailAddress",
            "example@mail.com"
        );

        Platform.Response.Write(Platform.Function.Stringify(result));
		
	} catch(error) {
        Platform.Response.Write(Platform.Function.Stringify(error));
    }
</script>
[
    {
        "_CustomObjectKey": 0,
        "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        "EmailAddress": "example@mail.com",
        "_CreatedDate": "2024-01-29T02:00:00.000"
    },
    {
        "_CustomObjectKey": 1,
        "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        "EmailAddress": "example@mail.com",
        "_CreatedDate": "2024-01-29T02:00:00.000"
    }
]

Retrieve multiple rows using multiple parameters

var name = "MyDataExtension";

var result = Platform.Function.LookupRows(
    name,
    ["EmailAddress","FirstName"],
    ["example@mail.com","John"]
);
<script runat="server">
	try {

        var name = "MyDataExtension";

        var result = Platform.Function.LookupRows(
            name,
            ["EmailAddress","FirstName"],
            ["example@mail.com","John"]
        );

        Platform.Response.Write(Platform.Function.Stringify(result));
		
	} catch(error) {
        Platform.Response.Write(Platform.Function.Stringify(error));
    }
</script>
[
    {
        "_CustomObjectKey": 0,
        "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        "EmailAddress": "example@mail.com",
        "FirstName": "John",
        "_CreatedDate": "2024-01-29T02:00:00.000"
    }
]

Core

var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

var de = DataExtension.Init(customerKey);

var result = de.Rows.Lookup(
    ["EmailAddress"], 
    ["example@mail.com"]
);
<script runat="server">

    Platform.Load("core", "1");

	try {

        var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

        var de = DataExtension.Init(customerKey);

        var result = de.Rows.Lookup(
            ["EmailAddress"], 
            ["example@mail.com"]
        );

        Write(Stringify(result));
		
	} catch(error) {
        Write(Stringify(error));
    }	

</script>
[
  {
    "_CustomObjectKey": 1,
    "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "FirstName": "John",
    "LastName": "Doe",
    "EmailAddress": "example@mail.com"
  }
]

Reference

Ressources and references related to the current methods.

Official documentation
SOAP object

Last Updated: