0

I am facing issues similar to this. I am using a very similar code. The ampscript executes twice and hence two emails are sent. My code is currently executing on the Interactive Form Cloud Page, which is a thankyou page, once the user submits the interactive form on the email. The thank you page then redirects to my client's website(which is externally hosted). My guess is that the ampscript is executing twice, once when the user clicks on submit and once when the thank you page redirects to the clients homepage.

The overall use case is after submission of the interactive form, a follow up email needs to be sent as soon as possible(hence triggered send) with personalization of the content of the form submitted. This is happening, only issue that the follow up email is getting sent twice.

Flow of my code:

  1. User recives an email with interactive form
  2. User submits the form and clicks on Submit
  3. The interactive form cloud page has a html code to show thank you message and a redirect to external website is configured.
  4. Has an ampscript below for triggered send:

Any help is appreciated!.

%%[
var @customerId,@customerInteractionInterest1,@customerInteractionInterest2,@customerInteractionInterest3,@customerInteractionInterest4,@ts, @tsDef, @ts_extkey, @ts_email, @ts_sub, @ts_statusCode, @ts_statusMsg, @errorCode

SET @customerId = RequestParameter('customerId')
SET @customerInteractionInterest1 = RequestParameter('customerInteractionInterest1')
SET @customerInteractionInterest2 = RequestParameter('customerInteractionInterest2')
SET @customerInteractionInterest3 = RequestParameter('customerInteractionInterest3')
SET @customerInteractionInterest4 = RequestParameter('customerInteractionInterest4')

SET @subscriberkey = Base64Decode(@customerId,'UTF-8')
SET @emailaddress = Lookup("ENT._Subscribers","EmailAddress","SubscriberKey",@subscriberkey)

SET @ts = CreateObject("TriggeredSend")
SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_extkey = "FollowUpEmail"

SetObjectProperty(@tsDef, "CustomerKey", @ts_extkey)
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
 
SET @ts_sub = CreateObject("Subscriber")
SetObjectProperty(@ts_sub, "EmailAddress",@emailaddress)
SetObjectProperty(@ts_sub, "SubscriberKey", @subscriberkey)
AddObjectArrayItem(@ts, "Subscribers", @ts_sub)

SET @ts_att = CreateObject("Attribute")
SetObjectProperty(@ts_att, "Name", "customerInteractionInterest1")
SetObjectProperty(@ts_att,"Value", @customerInteractionInterest1)
AddObjectArrayItem(@ts, "Attributes", @ts_att)

SET @ts_att = CreateObject("Attribute")
SetObjectProperty(@ts_att, "Name", "customerInteractionInterest2")
SetObjectProperty(@ts_att,"Value", @customerInteractionInterest2)
AddObjectArrayItem(@ts, "Attributes", @ts_att)

SET @ts_att = CreateObject("Attribute")
SetObjectProperty(@ts_att, "Name", "customerInteractionInterest3")
SetObjectProperty(@ts_att,"Value", @customerInteractionInterest3)
AddObjectArrayItem(@ts, "Attributes", @ts_att)

SET @ts_att = CreateObject("Attribute")
SetObjectProperty(@ts_att, "Name", "customerInteractionInterest4")
SetObjectProperty(@ts_att,"Value", @customerInteractionInterest4)
AddObjectArrayItem(@ts, "Attributes", @ts_att)

SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)
IF @ts_statusCode != "OK" THEN 
RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode)
ENDIF ]%%
  • If you could share the code, it would be helpful in troubleshooting. Is it self posting or is it hitting a second 'processing' page? Is there a third 'thank you' page? Where is the code to trigger the TSD at? The emails sent, are they both identical or are they different versions/info? – Gortonington Jan 12 at 15:21
  • You should integrate functionality that fast double clicking or stuff similar to this will not invoke your processing page twice. Another way to do this is that the processing page will first insert data into a dataextension and you check if the record already exists or not. You would then have a journey that only takes the newest unprocessed entries and sends out emails. But honestly i only came up with this solution because i do not have experience with TSD. Is there any cool documentation about that matter @Gortonington? – Johannes Schapdick Jan 12 at 15:32
  • @Gortonington: Updated my question above! – Swati Mishra Jan 12 at 16:00
  • 2
    This page likely isn't the problem, since it only does one thing -- how you're handling the form POST is where I would focus. – Adam Spriggs Jan 12 at 16:02
2

As both @AdamSpriggs and @JohannesSchapdick mentioned, I am assuming that the issue is potential double post on the form or other similar double running.

How I usually handle this is to wrap the triggered send information inside a conditional statement.

For this conditional statement you would need to:

  1. Have the Triggered Send Data Extension (TSD DE) name/key
  2. Have a field filled in with current date/time in the TSD DE
  3. Have an understanding of Date Math in AMPScript

So after having all that, I would wrap it into something like:

%%[
  SET @tsdDE = "mytriggerDE"
  SET @now = NOW()

  SET @lastSendRows = LOOKUPORDEREDROWS(@tsdDE,1,"SendDate DESC", "SubscriberKey",@subKey,"EmailAddress",@emailaddress)

  IF Rowcount(@lastSendRows) > 0 THEN
    SET @lastSendRow = Row(@lastSendRows,1)
    SET @lastSendDate = Field(@lastSendRow,"SendDate")
  ELSE
    SET @lastSendDate = @now /* To prevent potential error in DATEDIFF */
  ENDIF

  IF DATEDIFF(@lastSendDate,@now,'MI') > 30 OR ROWCOUNT(@lastSendRows) = 0 THEN

    /* TSD Code */

  ENDIF
]%%

This will do a lookup to the TSD DE to verify if the email has already been triggered in the last 30 minutes (can change timeline to whatever you want to limit it to) and if so, then it hides the trigger send code.

This way no matter if they do multiple clicks or its pulled in multiple times, it will only send once per 30 minutes (assuming 'keys' you want would be Subscriberkey and EmailAddress - you can adjust your 'keys' via the Lookuporderedrows if they are different.)

I haven't fully tested this down to seconds and milliseconds, but I believe it should handle that without issue.

  • Thanks @Gortonington, I will surely try this! – Swati Mishra Jan 13 at 7:38

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.