Prune rows in a Data Extension with SSJS

Say you want to delete a million rows from a Data Extension in Salesforce Marketing Cloud (SFMC). Doing that with the SFMC Web Services can be a pain. One alternative is to utilize Server-Side JavaScript (SSJS) and a Landing Page.

I built a landing page that posts to itself and runs this pruneRows() function. I configured a Data Extension that contains the keys to delete. The script retrieves all of the rows with that key, deletes them and updates the DE of keys with the results.

You may have to experiment with the number of Row Keys to retrieve at a time. If the number is too high, the landing page will time-out. In my scenario, I found that processing 50 at a time worked well (line #8).

For further reading:

Leave a Reply

2 Comment threads
5 Thread replies
Most reacted comment
Hottest comment thread
4 Comment authors
João MaranoJasonAdam SpriggsJoseph Recent comment authors
newest oldest most voted
Notify of

Hey Adam– love your stuff!

I was playing around implementing this but I’m terrible at javascript so wasn’t able to set this up. I started to look around alternative routes.

I was able to set this up using ampscript, and a nice little bonus — it doesn’t seem to require me to loop through 50 at a time.

code in landingpage:

VAR @timeBefore, @timeAfter, @count
SET @timeBefore = now()
SET @count=DeleteData(“DataExtensionToPrune”,”RowKey”,RowKey)
SET @timeAfter = now()

total deleted in batch: %%=v(@count)=%%

Started: %%=v(@timeBefore)=%%
Ended: %%=v(@timeAfter)=%%


This AMPscript seems straight forward but this doesn’t work for me. Is the a prerequisite?

João Marano

Hi, Adam. I made the purchase of your book: ‘The Guide of AMPSCRIPT’ and I would like to say that the book helps me a lot with my experience in Marketing Cloud. But now, I have a problem with SSJS, so I come to your blog to ask for help, kindly. In my context, I have a Data Extension (named: Count w Growth Rate-2) that is populate via integration. I lookup a report that I can accompany the growth rate by daily this Data Extension; In my search the best method is to create a Data Extension and populate this… Read more »