0

I am testing the code for a potential preference centre. I am passing the email address and subscriber key from an email and I am saving the data into a triggered send data extension which then sends an email with the confirmation of the selections.

All of this works; the only part of the code where I have issues with is the fact that in my triggered send data extension I see my record being added twice. Please see print screen attached & my code.

Any guidance how to correct this is appreciated:

%%[
var @key,@email,@ts, @tsDef, @ts_sub, @ts_attr, @tsctr, @ts_subkey, @ts_statusCode, @ts_statusMsg, @errorCode
set @key=QueryParameter("key")
set @email=QueryParameter("email")


if RequestParameter("submitted") == true then

  InsertData(
        "TriggeredSendDataBOZIPAGESSSSSSS",
        "SubscriberKey", RequestParameter("SubscriberKey"),
        "EmailAddress", RequestParameter("email"),
        "Preference1", RequestParameter("Preference1"),
        "Preference2", RequestParameter("Preference2"),
        "Newsletter", RequestParameter("Newsletter"),
        "Travel", RequestParameter("Travel")
       )
SET @ts = CreateObject("TriggeredSend")
SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_subkey=QueryParameter("key")
SetObjectProperty(@tsDef, "CustomerKey", "TRIGGEREDSENDSSSS")
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
SET @ts_sub = CreateObject("Subscriber")
SetObjectProperty(@ts_sub, "EmailAddress", QueryParameter("email"))
IF NOT EMPTY(@ts_subkey) THEN
    SetObjectProperty(@ts_sub, "SubscriberKey", @ts_subkey)
ELSE
    SetObjectProperty(@ts_sub, "SubscriberKey", QueryParameter("email"))
ENDIF
AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)

IF @ts_statusCode != "OK" THEN
    RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode)
ENDIF


endif

]%%

<!DOCTYPE html>
<html>
  <body>
      %%[ if RequestParameter("submitted") == true then ]%%
         <p>Thank you for submitting your details.</p>
      %%[ else ]%%
      <h2>Hello %%=v(@key)=%%</h2>

      <form action="%%=RequestParameter('PAGEURL')=%%" method="post">
         <label>Newsletter</label>
         <input type="radio" name="Newsletter" checked><br>
         <label>Travel</label>
         <input type="radio" name="Travel" checked><br>
         <label>SubscriberKey</label>
         <input type="text" name="SubscriberKey" value="%%=v(@key)=%%"><br>
         <label>Email</label>
         <input type="text" name="email"  value="%%=v(@email)=%%"><br>
         <label>Preference 1</label>
         <input type="text" name="Preference1"><br>
         <label>Preference 2</label>
         <input type="text" name="Preference2"><br>
         <input name="submitted" type="hidden" value="true" />
         <input type="submit" value="Submit">

      </form>
      %%[ endif ]%%
   </body>
</html>

Genter image description here

2

Triggering an email will automatically add a row to the Data Extension configured in the Triggered Send Definition. No need to add a row manually.

|improve this answer|||||
  • Right at @Giulietta, so like Adam said, you are getting two rows because the system is adding the row once, and your manual entry is adding it a second time. – garek007 Apr 24 '18 at 11:22
  • Thank you @Adam Spriggs &garek007. I was able to modify the script and now it works as it should – Giulietta May 2 '18 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.