I am using (SSJS +Ampscript) because i need to create dynamic variables.

I am upserting DE using ampscript and trying to look up same record using SSJS Rows.Lookup but still giving the old value not the upserted value. tried using ampscript lookup as well still its giving me the old value, i tried Rows.Retrieve with filter then its giving me the updated upserted value but its pretty slow. Not able to process 50 records where as Rows.Lookup process all the 3k records. I need that latest upsert lookup to skip duplication. if the combination of Emailaddress, subscriberkey, ordernumber and saleid exists, i dont need to upsert or insert.

for (var i = 0; i < records.length; i++) {
    var json = records[i]["Json"]
    var obj = Platform.Function.ParseJSON(json);

    Platform.Variable.SetValue("@subscriberkey", records[i]["SubscriberKey"]);
    Platform.Variable.SetValue("@email", records[i]["EmailAddress"]);
    Platform.Variable.SetValue("@countrycode",  records[i]["CountryCode"]);
    Platform.Variable.SetValue("@languagecode", records[i]["LanguageCode"]);
    Platform.Variable.SetValue("@customernumber", records[i]["CustomerNumber"]);
    Platform.Variable.SetValue("@firstname", obj.customer.Firstname);
    Platform.Variable.SetValue("@lastname", obj.customer.LastName);
    Platform.Variable.SetValue("@saleid", obj.Order.SaleId);

    var DE1 = DataExtension.Init(enrinchedDEcustomerKey);
    var matchprodbegin1 = DE1.Rows.Lookup(
        ["SubscriberKey", "EmailAddress", "SaleId", "OrderNumber"],
        [records[i]["SubscriberKey"], records[i]["EmailAddress"],
         obj.Order.SaleId, obj.Order.OrderNumber]

    if (matchprodbegin1.length == 0) {
        for (var j = 0; j < obj.Order.Items.length; j++) {
            var loopNr = j+1; // Add 1 because loop starts at 0
            var ItemName = "@ItemName"+loopNr;
            var ItemCode = "@ItemCode"+loopNr;
            var Size = "@Size"+loopNr;
            var Image = "@Image"+loopNr;
            var Fit = "@Fit"+loopNr;
            var Fabric = "@Fabric"+loopNr;
            var Buttons = "@Buttons"+loopNr;
            var Lining = "@Lining"+loopNr;
            var Turnup = "@Turnup"+loopNr;
            var Waistband = "@Waistband"+loopNr;

            // Write variable to AMPscript for further processing
            Platform.Variable.SetValue(ItemName, obj.Order.Items[j].ItemName);
            Platform.Variable.SetValue(ItemCode, obj.Order.Items[j].ItemCode);
            Platform.Variable.SetValue(Size, obj.Order.Items[j].Size);
            Platform.Variable.SetValue(Image, obj.Order.Items[j].Image);
            Platform.Variable.SetValue(Fit, obj.Order.Items[j].Fit);
            Platform.Variable.SetValue(Fabric, obj.Order.Items[j].Fabric);
            Platform.Variable.SetValue(Buttons, obj.Order.Items[j].Buttons);
            Platform.Variable.SetValue(Lining, obj.Order.Items[j].Lining);
            Platform.Variable.SetValue(Turnup, obj.Order.Items[j].Turnup);
            Platform.Variable.SetValue(Waistband, obj.Order.Items[j].Waistband);

        var resp = ampScript(
            "if empty(@subscriberkey) or empty(@email) or "
            + "empty(@saleid) or empty(@ordernumber) then else "
            + "SET @rows = UpsertData(@targetDE, 4, 'SubscriberKey', @subscriberkey, "
            + "'EmailAddress', @email, 'SaleId', @saleid, "
            + "'OrderNumber', @ordernumber, 'FirstName', @firstname, "
            + "'LastName', @lastname, 'CustomerNumber', @customernumber, "
            + "'CountryCode', @countrycode, 'LanguageCode', @languagecode, "
            + "'ItemName1', @ItemName1, 'ItemCode1', @ItemCode1, "
            + "'Size1', @Size


You must log in to answer this question.

Browse other questions tagged .