I am having issues making a dynamic trigger send using AMPscript. My goal is to create a script that will send out a triggered email based on the selection they make in the form. Choice 1 will provide email 1, etc. I also am working on making it so that if they already submitted and received the email, it will not send it again or upload again.
On a single trigger definition, with the keys and all hard coded, it seems to work 100%, but once I added in variables it does not seem to work correctly. All the information seems to fill correctly (pulling variable values into landing page via v() function), but the email does not send nor is the subscriber added to the trigger DE.
See below for my current AMPScript:
%%[
var @emailaddr, @ts, @tsDef, @ts_subkey, @ts_sub, @ts_statusCode, @errorCode, @lookuptrigger, @DEtrigger, @Secret, @triggerkey
SET @emailaddr = RequestParameter('EmailAddress')
SET @Secret = RequestParameter('Secret')
IF @Secret=="1" THEN
SET @DEtrigger="Trigger1"
SET @triggerkey="triggertest"
ELSEIF @Secret=="2" THEN
SET @DEtrigger="Trigger2"
SET @triggerkey="triggertest2"
ELSEIF @Secret=="3" THEN
SET @DEtrigger="Trigger3"
SET @triggerkey="triggertest3"
ENDIF
IF NOT EMPTY(@DEtrigger) THEN
Set @lookuptrigger = Lookup(@DEtrigger, "EmailAddress", "EmailAddress", @emailaddr)
ELSE
SET @lookuptrigger = "new"
ENDIF
IF EMPTY(@lookuptrigger) THEN
SET @ts = CreateObject("TriggeredSend")
SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_subkey = @emailaddr
SetObjectProperty(@tsDef, "CustomerKey", @triggerkey)
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
SET @ts_sub = CreateObject("Subscriber")
SetObjectProperty(@ts_sub, "EmailAddress", @emailaddr)
IF NOT EMPTY(@ts_subkey) THEN
SetObjectProperty(@ts_sub, "SubscriberKey", @ts_subkey)
ELSE
SetObjectProperty(@ts_sub, "SubscriberKey", @emailaddr)
ENDIF
AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
ELSE
SET @ts="none"
ENDIF
]%%
Below is the hard coded version that works:
%%[
var @emailaddr, @ts, @tsDef, @ts_subkey, @ts_sub
SET @emailaddr = "[email protected]"
SET @ts = CreateObject("TriggeredSend")
SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_subkey = @emailaddr
SetObjectProperty(@tsDef, "CustomerKey", "triggertest")
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
SET @ts_sub = CreateObject("Subscriber")
SetObjectProperty(@ts_sub, "EmailAddress", @emailaddr)
IF NOT EMPTY(@ts_subkey) THEN
SetObjectProperty(@ts_sub, "SubscriberKey", @ts_subkey)
ELSE
SetObjectProperty(@ts_sub, "SubscriberKey", @emailaddr)
ENDIF
AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
]%%
Upon inspection, it appears to be an issue with the 'RequestParameter' being set for pulling the email address that is causing issues as it keeps throwing the error that there is no valid subscriber.