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:

3
Leave a Reply

avatar
1 Comment threads
2 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
JasonAdam SpriggsJoseph Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Joseph
Guest
Joseph

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)=%%

Jason
Guest
Jason

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