I've got a data extension with over 2500 records in it that I'm trying to modify as such: take the 'ContactKey' value, encrypt it using EncryptSymmetric() in AMPscript, and then assign the 'Encrypted ContactKey' value to the result. Here's my code:
SSJS:
<!--%%[--><div><p id="secret" style="font-size: 40px; text-align: center;"> Click to Edit SSJS</p></div><!--]%%--><!-- SSJS Header --><script runat="server"> Platform.Load("core", "1"); try { // SSJS Header // SSJS Core var moreData = true; var lbcClients = DataExtension.Init("LBC-Clients"); var data = [1]; while (moreData) { data = lbcClients.Rows.Retrieve({ Property: "Unencrypted", SimpleOperator: "equals", Value: 1 }); if (data.length > 0) { // Process your data here for (var i = 0; i < data.length; i++) { var contactKey = data[i].ContactKey; Write("ContactKey: " + contactKey +"<br>"); Variable.SetValue('@ContactKey', contactKey); Platform.Function.TreatAsContent(Platform.Function.ContentBlockByID("1288227")); encryptedContactKey = Variable.GetValue("@EncryptedContactKey"); Write("Encrypted ContactKey: " + encryptedContactKey +"<br><br>"); // Update the "Unencrypted" field to 0 lbcClients.Rows.Update({Unencrypted: 0}, ["ContactKey"], [contactKey]); lbcClients.Rows.Update({"Encrypted ContactKey": encryptedContactKey}, ["ContactKey"], [contactKey]); } } else { moreData = false; } } // SSJS Core // SSJS Footer } catch(error) { var formattedError = Stringify(error); formattedError = formattedError.replace(/\\r\\n/g, "<br><br>").replace(/\\n/g, "<br><br>").replace(/\\r/g, "<br><br>"); Write(formattedError); }</script><!-- SSJS Footer -->
AMPscript:
<!--%%[--><div id="secret" style="font-size: 40px; text-align: center;"> Click to Edit AMPscript</div><!--]%%--><!--%%[/* Initialize variables */VAR @SymKey, @Salt, @IV /*, @ExecutionLog, @EncryptedContactKey *//* Set encryption keys using External Keys from Key Management in Marketing Cloud Setup */SET @SymKey = "285b8e90-d5bf-4777-a634-10c3a7aa4005"SET @Salt="2c0395d5-63bb-4cab-9f11-2cea7e2c811c"SET @IV = "c1e8c783-f4e7-45e7-8a5b-45d4d61aa15a"/*SET @ExecutionLog = CONCAT("AMPscript execution started...")SET @ExecutionLog = CONCAT(@ExecutionLog, ",ContactKey: ", @ContactKey)*/SET @EncryptedContactKey = EncryptSymmetric(@ContactKey, 'aes', @SymKey, @null, @Salt, @null, @IV, @null)/*SET @ExecutionLog = CONCAT(@ExecutionLog, ",Encrypted ContactKey: ", @EncryptedContactKey)SET @ExecutionLog = CONCAT(@ExecutionLog, ",AMPscript execution finished...")*/]%%-->
I'm certain that the formatting at the top does not interfere, but I included it for transparency. There's also a lot of commenting and logging that's either toggled on or off, which I'm only fairly certain isn't interfering.
My main issue is in the batching of the necessary repeated calls of Rows.Retrieve() to iterate over all of the records in the data extension. When I run this on a CloudPage, it only ever performs the task on 2500 of the records, leaving out the rest. The CloudPage, however, times out and gives a "We couldn't open this page. Try again later." error.
Any help is appreciated.