Retrieve a Data Extension record verified

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

Core

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

var de = DataExtension.Init(customerKey);

var result = de.Rows.Retrieve({
    Property: "LastName", 
    SimpleOperator: "equals", 
    Value: "Doe" 
});
<script runat="server">

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

	try {

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

        var de = DataExtension.Init(customerKey);

        var result = de.Rows.Retrieve({
            Property: "LastName", 
            SimpleOperator: "equals", 
            Value: "Doe" 
        });

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

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

WSProxy

var api = new Script.Util.WSProxy();

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

var result = api.retrieve(
    "DataExtensionObject[" + customerKey + "]", 
    [
        "FirstName", 
        "LastName",
        "EmailAddress"
    ]
);
<script runat="server">

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

    var api = new Script.Util.WSProxy();

	try {

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

        var result = api.retrieve(
            "DataExtensionObject[" + customerKey + "]", 
            [
                "FirstName", 
                "LastName",
                "EmailAddress"
            ]
        );

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

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "Name": null,
            "Keys": null,
            "Type": "DataExtensionObject",
            "Properties": [
                {
                    "Name": "FirstName",
                    "Value": "John"
                },
                {
                    "Name": "LastName",
                    "Value": "Doe"
                },
                {
                    "Name": "EmailAddress",
                    "Value": "example@mail.com"
                }
            ],
            "Client": null,
            "PartnerKey": null,
            "PartnerProperties": null,
            "CreatedDate": "0001-01-01T00:00:00.000",
            "ModifiedDate": null,
            "ID": 0,
            "ObjectID": null,
            "CustomerKey": null,
            "Owner": null,
            "CorrelationID": null,
            "ObjectState": null,
            "IsPlatformObject": false
        }
    ],
    "HasMoreRows": false
}

TIP

DataExtensionObject[Name] also works, unless > 36 characters.

Reference

Ressources and references related to the current methods.

Official documentation
Data Extensions Async API
SOAP object

Help me turn coffee into code

This website is provided to you free of charge. However, a lot of time and effort are spent to write, test and mainain the code. Please consider supporting my work by buying me a cup of coffee.

Last Updated: