Is there any way of doing something like,

<script runat=server>
    //initialize DE
    var _Sent = DataExtension.Init("_Sent");
    //retrieve data
    var _Sent_data = _Sent.Rows.Retrieve();
    Write("Length: " + _Sent_data.length); //returns 0

What would the external key for a system dataview be?


The only possible way I know of to do this is via the SOAP API. But I would never use this to retrieve all the _Sent Dataview as it will time out without a doubt. Most Sent Dataviews contain a minimum of millions of records (6 months worth of sends) which is too much for any landing page or script activity to parse through.

So, judging from your question it looks like you are just looking for the size (length) of the _Sent object which can be obtainable, just through a different means.

  1. I would create a DE that contains all the _Sent Dataview fields
  2. Then create a SQL query to fill this DE with all the info from the Dataview
  3. Then you can use DataExtensionRowCount() in AMPScript to retrieve the rowcount of that DE.

Sample of Query:

FROM _Sent

Sample of AMPScript:

%%[ SET @SentCount = DataExtensionRowCount("mySentDataViewDE") ]%%

You can then put that query in an automation and schedule it to run at a timeframe you need it to and keep it as up to date as necessary.


You can't retrieve data views using core SSJS functions, but you can using the LookupRows or LookupOrderedRows platform functions (which are effectively a wrapper for the corresponding AMPscript function). The following code will retrieve the first 2,000 records from the _Sent Data view for a given MID:

Platform.Function.LookupRows('_Sent', 'AccountID', 12345678);

However, as Greg points out, I'd recommend using a Query Activity if you need to retrieve more than 2,000 records from a Data View.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.