0

i am very new for marketing cloud and I am having this problem.I have a Data Extention containig a list of Subscribers with their email and subscriber key.I build a form working well, which can post entery in to DE but i want to stop users to send this form more then once. IF the user alredy in DE must redirect to other page name : you already signed in. i have the following code but somehow create always new record insted of updating the existing record. Thanks alot for your help.

var idRows = Platform.Function.LookupRows('IDE_Form_Data','IDE_Form_Data_Key',IDE_Form_Data_Key);
            if(idRows>0) {
              Platform.Function.UpdateData("IDE_Form_Data",["IDE_Form_Data_Key"],[IDE_Form_Data_Key],["Fieldvalue_txt_1", "Form_Phone_Num", "Subscriber_Key", "Form_Id", "Form_Name", "Form_Type", "Fieldname_txt_1", "Journey_Desc", "Form_Insert_Date"],[Fieldvalue_txt_1,Form_Phone_Num,Subscriber_Key,Form_Id,Form_Name,Form_Type,Fieldname_txt_1,Journey_Desc,DateTime.SystemDateToLocalDate(Now())]);
              Platform.Response.Redirect("https://youalreadysignedinpage", false);
            } else {
              Platform.Function.InsertDE("IDE_Form_Data",["IDE_Form_Data_Key", "Fieldvalue_txt_1", "Form_Phone_Num", "Subscriber_Key", "Form_Id", "Form_Name", "Form_Type", "Fieldname_txt_1", "Journey_Desc", "Form_Insert_Date"],[IDE_Form_Data_Key,Fieldvalue_txt_1,Form_Phone_Num,Subscriber_Key,Form_Id,Form_Name,Form_Type,Fieldname_txt_1,Journey_Desc,DateTime.SystemDateToLocalDate(Now())]);
            }
            Platform.Response.Redirect("https://thankyoupage", false);
3
  • Do you try to set a fixed existing record to test yet?
    – Duc Le
    Commented Jan 10, 2023 at 12:16
  • yes i do have existing record to test
    – hilmi
    Commented Jan 10, 2023 at 12:18
  • and everytime create a new Record in Data Extention when i send the Form :(
    – hilmi
    Commented Jan 10, 2023 at 12:50

1 Answer 1

1

The LookupRows function will return an array if a rowset is found. So your check condition was wrong. You can read the examples of the function to understand.

Try this:

var idRows = Platform.Function.LookupRows('IDE_Form_Data','IDE_Form_Data_Key',IDE_Form_Data_Key);
            if(idRows && idRows.length > 0) {
              Platform.Function.UpdateData("IDE_Form_Data",["IDE_Form_Data_Key"],[IDE_Form_Data_Key],["Fieldvalue_txt_1", "Form_Phone_Num", "Subscriber_Key", "Form_Id", "Form_Name", "Form_Type", "Fieldname_txt_1", "Journey_Desc", "Form_Insert_Date"],[Fieldvalue_txt_1,Form_Phone_Num,Subscriber_Key,Form_Id,Form_Name,Form_Type,Fieldname_txt_1,Journey_Desc,DateTime.SystemDateToLocalDate(Now())]);
              Platform.Response.Redirect("https://youalreadysignedinpage", false);
            } else {
              Platform.Function.InsertDE("IDE_Form_Data",["IDE_Form_Data_Key", "Fieldvalue_txt_1", "Form_Phone_Num", "Subscriber_Key", "Form_Id", "Form_Name", "Form_Type", "Fieldname_txt_1", "Journey_Desc", "Form_Insert_Date"],[IDE_Form_Data_Key,Fieldvalue_txt_1,Form_Phone_Num,Subscriber_Key,Form_Id,Form_Name,Form_Type,Fieldname_txt_1,Journey_Desc,DateTime.SystemDateToLocalDate(Now())]);
            }
            Platform.Response.Redirect("https://thankyoupage", false);
6
  • Hi i rebuild my if condition but still i have the same problem :(
    – hilmi
    Commented Jan 10, 2023 at 17:59
  • @hilmi If you set a fixed value in IDE_Form_Data_Key variable which you already know is from an existing record. What is the page it would redirect to? Does it create a new record in the DE?
    – Duc Le
    Commented Jan 11, 2023 at 1:35
  • If the form is in a Cloudpage, you need to save and republish it as well
    – Duc Le
    Commented Jan 11, 2023 at 1:45
  • i figured out and i dont have a fixed record for IDE_Form_Data_Key (its change always)but i do have a fixed record for Subscriber_Key. So i need to use Subscriber_Key insted of Ide_Form_Data_Key.the Form is in CLoudpage like you said but somehow i think i need a for loop right ? but how can i ask to marketing cloud ?if user already exist with same SUbscriber_Key then dont write in DE but redirect to other page
    – hilmi
    Commented Jan 11, 2023 at 9:31
  • and one more quation what exacly do this line of code ? i Mean sure its lookupRows func bring me where i want to select but what is the perpuse of this -- if (idRows && idRows.lengt >0)
    – hilmi
    Commented Jan 11, 2023 at 9:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .