[SalesForce] How to add Attributes to a TriggeredSendDefinition on LandingPage

I am creating a landing page with a form. On submit, the form passes variables to another landing page that will process and perform three different tasks, two of which are performing a TriggeredSend via InvokeCreate().

I am able to generate the TriggeredSend email, however when I attempt to pass through Attributes for the TS, I am met with the error:

Unable to queue Triggered Send request. There are no valid subscribers.

Here is my AMPscript:

%%[

VAR @emailaddr, @MembershipID, @Member_ID, @FirstName, @ts, @ts_def, @ts_externalkey, @ts_sub, @ts_attr, @ts_statusCode, @ts_statusMsg, @errorCode

SET @emailaddr = "myemailaddress@email.com"

/* Retrieve the POST variables*/

SET @MembershipID = RequestParameter("MembershipID")
SET @Member_ID = RequestParameter("Member_ID")
SET @FirstName = RequestParameter("FirstName")

/* Create the Objects  for the TriggeredSend*/

SET @ts = CreateObject("TriggeredSend")
SET @ts_def = CreateObject("TriggeredSendDefinition")

SetObjectProperty(@ts_def, "CustomerKey", "13323_01137")

SetObjectProperty(@ts, "TriggeredSendDefinition", @ts_def)

SET @ts_sub = CreateObject("Subscriber")
SetObjectProperty(@ts_sub, "EmailAddress", @emailaddr)
SetObjectProperty(@ts_sub, "SubscriberKey", @emailaddr)

SET @ts_attr = CreateObject("Attribute")
SetObjectProperty(@ts_attr, "Name", "Member_ID")
SetObjectProperty(@ts_attr, "Value", @Member_ID)
AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)

SET @ts_attr = CreateObject("Attribute")
SetObjectProperty(@ts_attr, "Name", "MembershipID")
SetObjectProperty(@ts_attr, "Value", @MembershipID)
AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)

SET @ts_attr = CreateObject("Attribute")
SetObjectProperty(@ts_attr, "Name", "FirstName")
SetObjectProperty(@ts_attr, "Value", @FirstName)
AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)

AddObjectArrayItem(@ts, "Subscribers", @ts_sub)

/*
SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)

IF @ts_statusCode != "OK" THEN
    VAR @CompleteRows, @RaiseErrorID
    SET @CompleteRows =  LookupRows("RaiseError_Log","StaticField","RaiseError")    
    SET @RaiseErrorID = ADD(RowCount(@CompleteRows),1)
InsertDE("RaiseError_Log","RaiseErrorID",@RaiseErrorID,"ClientID",memberid,"SendID",jobid,"SubscriberKey",_subscriberkey,"EmailAddress",emailaddr,"EmailName",emailname_,"ListID",listid,"ErrorDate",NOW(),"ErrorDescription",@errorCode)       

    RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode)
ELSE ]%%

The email seemed to have sent OK.

%%[ENDIF]%%

The TriggeredSend Interaction is set up using a Data Extension. I pass attributes directly to a TriggeredSend via SOAP – is this not possible with AMPscript?

Best Answer

First - you are on the right track using the ampscript on the landing page. It's easier that way versus trying to build out a soap call.

Provided that you are not adding to a list with the Triggered Send interaction - your syntax should work.

The error "no valid subscribers" means some data is not matching up in the TriggeredSend Data extension or the List you are adding to (nullable value in a non-nullable field, wrong data type like the DE has a number while the data has an alpha-numeric value - etc). You did a great job, because it seems you have isolated it to the Member_ID value.

I would try to first start by simply try to rename variables the variables you declared in the ampscript.

I've run into a problem where the variables could already been (what seems to be "secretly") declared as pre-defined system variables or already defined as an attribute. So the script could essentially be getting confused between what you are trying to call - the attribute/system variable called "Memeber_ID" or the variable called "Member_ID" in the ampscript which is housing the data you got from the URL.

Try This:

VAR @MemID
SET @MemID = RequestParameter("Member_ID")

Then in your build:

SET @ts_attr = CreateObject("Attribute")
SetObjectProperty(@ts_attr, "Name", "Member_ID")
SetObjectProperty(@ts_attr, "Value", @MemID)
AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)

You might want to also consider doing the same for @EmailAddr since %%EmailAddr%% is definitely a predefined system attribute.

Not saying it's the answer, but it might be worth a shot before you start dissecting the process.

Related Topic