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:
- User recives an email with interactive form
- User submits the form and clicks on Submit
- The interactive form cloud page has a html code to show thank you message and a redirect to external website is configured.
- 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 ]%%