UpdateDE with SSJS and Multiple Conditions

dataextensionsmarketing-cloudssjs

I haven't seen any questions or answers that pertain to this exact type of situation, so I am hoping for a little help. I'm trying to update a bit of SSJS that I use to essentially find-and-replace DE column data when necessary. It works great when I'm trying to update based on one piece of column data (like all people who are in zip code XXXXX will get an updated URL in the "link" column) but I have a request to update all customers within 72 zip codes and it doesn't seem to be working. Here's my reference material: SSJS Guide

I am doing this in SSJS because the email template we use for this deployment is meant to be a sort of "set and forget" type of template where we just overwrite the DE with fresh new customer data, but sometimes the DE has mistakes in it and that's where this fix comes in handy. I've just never been faced with more than one item to use as a "key" like I do now.

Here is what my code looks like, with some generic replacement text to protect information:

<script runat="server">
// UPDATES DE WHEN CHANGES ARE REQUIRED
    //1. DE Name 
    //2. Column Name as Key
    //3. Column Values Filter (not req but can replace targeted values) 
    //4. Column Name for Update 
    //5. Column Value to Update (like new URL)
    var rows = Platform.Function.UpdateDE("Data_Extension_Name",["zip"],["08002","08003","08026","08033","08034","08043","08053","08054","08055","08052","08101","08102","08103","08104","08105","08107","08108","08109","08110","08009","08012","08021","08028","08071","08080","08081","08091","08094","08007","08010","08014","08016","08020","08025","08027","08029","08030","08031","08035","08036","08039","08045","08046","08048","08049","08051","08056","08057","08059","08060","08061","08062","08063","08065","08066","08073","08074","08075","08076","08077","08078","08083","08084","08085","08086","08090","08093","08096","08097","08099","08106","08518"],["Column 1 To Update","Column 2 To Update"],["Column 1 Updated Content","Column 2 Updated URL"]);
</script>

Any help would be much appreciated, or if there is another means of finding and updating data in 2 columns based on 72 zip codes, well, I'm all ears! Thanks in advance for any assistance as I really don't want to run this code 72 times. Cheers!

Best Answer

I was researching this and got to thinking about it after posting the question and I stumbled upon an answer. I thought I could loop the zip codes after putting them in an array. Just as I was thinking about this someone from the Email Geeks Slack channel responded, so I figured I'd answer my own question in case someone else has a similar issue:

<script runat="server">    
    var zipArray = ["08002","08003","08026","08033","08034","08043","08053","08054","08055","08052","08101","08102","08103","08104","08105","08107","08108","08109","08110","08009","08012","08021","08028","08071","08080","08081","08091","08094","08007","08010","08014","08016","08020","08025","08027","08029","08030","08031","08035","08036","08039","08045","08046","08048","08049","08051","08056","08057","08059","08060","08061","08062","08063","08065","08066","08073","08074","08075","08076","08077","08078","08083","08084","08085","08086","08090","08093","08096","08097","08099","08106","08518"];
    
    for (var i = 0; i < zipArray.length; i++) {
        var rows = Platform.Function.UpdateDE("Data_Extension_Name",["zip"],[zipArray[i]],["Column 1 To Update","Column 2 To Update"],["Column 1 Updated Content","Column 2 Updated URL"]);
    }
</script>
Related Topic