0

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.

4
  • Can you post the hard-coded version of the code that works so we can compare?
    – Jon Sakas
    Commented Apr 8, 2015 at 2:55
  • It's exact same code but top "secret" if statement is not there and de trigger and de key are not variables but instead the actual names. Commented Apr 8, 2015 at 10:47
  • I noticed that you have no default case for your IF block that switches on @Secret. Have you verified the value on @Secret?
    – Timothy
    Commented Apr 8, 2015 at 12:58
  • yes - I left that as blank for a default to make sure it does not send if there is not a value for '@Secret. I have verified that @Secret does have a value on each send though. (I use %%=v()=%% on landing page to fill variable onto the page itself) After inspection into the API call I have found the issue seems to be with the requestparameter function despite it showing being correctly filled and being used no problem in other AMPscript blocks. Commented Apr 8, 2015 at 13:04

1 Answer 1

0

The issue appears to have been email address validation. The above code will work correctly as long as the email address provided by Parameter is considered a valid address by Exact Target (which is weird because the email address WILL work regardless of ET filters when hard coded in...).

I apologize for the silly error and thanks all for your help.

You must log in to answer this question.

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