0

I am facing issues with below AMPscript.

I want to create a Cloudpage with First Name, Last Name and Email fields.
Once the user submits the page, the triggered email should be sent to that email id. But the page is showing an error.

The issue is only with AMPscript and not Triggered send definition.


        %%[
    VAR @ts, @tsDef, @ts_extkey, @ts_email, @ts_sub, @ts_statusCode, @ts_statusMsg, @errorCode, @firstname, @lastname, @Fname, @Lname

    set @firstname = RequestParameter('firstName')
    set @lastname = RequestParameter('lastName')
    SET @ts = CreateObject("TriggeredSend")
    SET @tsDef = CreateObject("TriggeredSendDefinition")
    SET @ts_extkey = "14631" 
    SET @ts_email = RequestParameter('EmailAddress')

    SetObjectProperty(@tsDef, "CustomerKey", @ts_extkey)
    SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)

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

    SET @Fname = CreateObject("Attribute") /*Attribute creation depends on the number of fields in DE*/
    SetObjectProperty(@Fname, "Name", "firstName") 
    SetObjectProperty(@Fname,"Value", @firstname) /* call the firstname variable declared above*/
    AddObjectArrayItem(@ts, "Attributes", @Fname)

    SET @Lname = CreateObject("Attribute")
    SetObjectProperty(@Lname, "Name", "lastName")
    SetObjectProperty(@Lname,"Value", @lastname) /* call the lastname variable declared above*/
    AddObjectArrayItem(@ts, "Attributes", @Lname)

    AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
    SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)

    ]%%

    %%=v(@ts_statusCode)=%%

    <form action="%%=RequestParameter('PAGEURL')=%%" method="post">

    <label>First Name</label> <br>
    <input type="text" name="firstName"> <br>

    <label>Last Name</label> <br>
    <input type="text" name="lastName"> <br>

    <label>Email</label> <br>
    <input type="text" name="EmailAddress"> <br> <br>

    <input id="submitted" type="hidden" name="submitted" value="submitted" />

    <input type="submit" value="Submit">
    </form>

    %%=IIF(RequestParameter("submitted") == "submitted", '<p>Your form has been submitted.</p>','')=%%

    </body>
    </html>

  • 1
    You need to have a conditional around the Trigger API AMPscript so it doesn't run when you first load it. something like %%[ IF RequestParameter("submitted ") == "submitted" THEN /* your Trigger AMpscript here*/ ENDIF ]%%. Right now it is trying to run the Trigger AMPscript without a firstname, lastname or email, which is causing it to error. – Gortonington Dec 3 '19 at 14:00
1

Under the assumption that this resolved his issue, I am moving this from a comment to an answer for easier reference:

You need to have a conditional around the Trigger API AMPscript so it doesn't run when you first load it.

Something like:

%%[ 
   IF RequestParameter("submitted ") == "submitted" THEN 
     /* your Trigger AMpscript here*/ 
   ENDIF 
]%%

Right now it is trying to run the Trigger AMPscript without a firstname, lastname or email, which is causing it to error.

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.