0

We created a fully-functional web-page collection in Marketing Cloud comprised of a form page and a thank-you-page. We tested it out and it works fine, i.e. after the form is filled out the data lands in the target data extension.

Now, we would like to also send a confirmation email to people who filled out the form. After creating and starting a triggered email, I've re-used an AMPscript code snippet for a triggered send on the second landing page (thank-you-page).

However, when I tried testing it, after filling out the form, I get a 500 error. The triggered Data Extension only has the default 2 fields + one that I added - CustomerID.

Below's the code I used:

        %%[ /* Page 1 */
        VAR @externalID, @url
        SET @externalID=RequestParameter('CustomerID')
        SET @url=CloudPagesURL(1691,'CustomerID', @externalID)
        ]%%
    <!-- HTML - form part - page 1 -->
    <div class="optin-form">
                 <form action="%%=CloudPagesURL(1691)=%%" method="GET">
                   <div class="form-group">
        <label for="textArea1">Question 1?
    </label>
        <textarea class="form-control" name="textArea1" id="textArea1" rows="8"></textarea>
      </div>
                   <div class="form-group">
        <label for="textArea2">Question 2? 
    </label>
        <textarea class="form-control" name="textArea2" id="textArea2" rows="8"></textarea>
      </div>
                    <div class="btn-wrapper">
                      <button class="btn btn-default" type="submit">Submit</button>
                    </div>
                    <input type="hidden" name="CustomerID" value="%%=v(@externalID)=%%">
                  </form>

                  </div>
                </div>
              </div>
            </div>
          </div>
        %%[
        /*Page 2 AMPscript - validation */

        %%[

        VAR @externalID, @extID, @url, @textArea1, @textArea2

        SET @externalID=RequestParameter('CustomerID')


        SET @textArea1 = RequestParameter('textArea1')
        SET @textArea2 = RequestParameter('textArea2')

        IF NOT EMPTY(@textArea1) THEN
        UpsertDE('Key_Priorities', 1, 'CustomerID', @externalID, 'Employee_life', @textArea1)
        ENDIF

        IF NOT EMPTY(@textArea2) THEN
        UpsertDE('Key_Priorities', 1, 'CustomerID', @externalID, 'Customer_life', @textArea2)
        ENDIF

        SET @url=CloudPagesURL(1690, 'CustomerID', @externalID)

    ]%%

%%[

VAR @externalID,@Email, @extID, @url, @textArea1, @textArea2

SET @externalID=RequestParameter('CustomerID')
SET @Email=RequestParameter('email')
SET @textArea1 = RequestParameter('textArea1')
SET @textArea2 = RequestParameter('textArea2')

IF NOT EMPTY(@textArea1) THEN
UpsertDE('IntSurvey', 1, 'CustomerID', @externalID, 'Employee_life', @textArea1)
ENDIF

IF NOT EMPTY(@textArea2) THEN
UpsertDE('IntSurvey', 1, 'CustomerID', @externalID, 'Customer_life', @textArea2)
ENDIF

IF NOT EMPTY(@Email) THEN
UpsertDE('IntSurvey', 1, 'CustomerID', @externalID, 'Email_Address', @Email)
ENDIF

SET @url=CloudPagesURL(1728, 'CustomerID', @externalID)

]%%

<script runat="server">

var customerID = Variable.GetValue('@externalID')
var emailAddress = Variable.GetValue('@Email')

var prox = new Script.Util.WSProxy();

var subKey = emailAddress

var customerKey = "Form-triggered-send";

var ts= {
       TriggeredSendDefinition: {CustomerKey: customerKey}
       ,Subscribers: [ {
              EmailAddress: emailAddress
            , SubscriberKey: subKey
            , Attributes: [
                {
                 Name: 'CustomerID',
                  Value: customerID
               }
            ]
        }]

    };

var res = prox.createItem("TriggeredSend", ts);

</script>


    <!-- html page 2- form continue-->
    <div class="background-gradiant">
      <form action="%%=CloudPagesURL(1690)=%%" method="post">
          <div class="container">
            <div class="row">
              <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
              </div>
              <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3 background-white">

                <div class="title-h3" style="color: #000000;">Thank You!</div>
              </div>
            </div>
          </div>
      </form>
        </div>

2 Answers 2

2

I honestly would utilize WSProxy for this as it is more performant, simpler to write and maintain. Something like the below would work:

<script runat="server">

var customerID = Variable.GetValue("@CustomerID")

var prox = new Script.Util.WSProxy();

var emailAddress = '[email protected]'
var subKey = emailAddress

var customerKey = "48047";

var ts= {
       TriggeredSendDefinition: {CustomerKey: customerKey}
       ,Subscribers: [ {
              EmailAddress: emailAddress
            , SubscriberKey: subKey
            , Attributes: [
                {
                 Name: 'CustomerID',
                  Value: customerID
               }
            ]
        }]

    };

var res = prox.createItem("TriggeredSend", ts);

</script>

Now in order to debug (in case the issue is with the info in the TSD call, I would insert a SSJS Try/Catch around it to get better error messaging. Something like:

<script runat=server>
try {
</script>
%%[ my AMPscript ]%%
<script runat=server>
} catch(e) {
  Platform.Response.Write(Stringify(e))
}
</script>

or

<script runat=server>
try {
 //my JS for Trigger
} catch(e) {
  Platform.Response.Write(Stringify(e))
}

This should then output on the page the error you are receiving when attempting the Trigger call and help you to resolve the error.

4
  • Tnx Gortonington. Since I have predominately used AMPscript, and have minor experience with SSJS, where should I paste this code? Into the second page, at the end of the html? Secondly, will this code send an email to any new contact's respective email address? I'm asking because from the old snippet I have the hard-coded email address value.
    – nix9247
    Commented Feb 18, 2020 at 14:40
  • You would put it where you currently have the AMPscript at. And no, I hardcoded the email as you had it in your example. You would need to pass the emailaddress in as a variable. If it seems more effort than value, by all means keep with the AMPscript - just try the debug (try/catch) around it to see if you can get a more specific error. Commented Feb 18, 2020 at 14:50
  • Hi, I added your code into my original code and remove hard-coded email. Can you take a look?
    – nix9247
    Commented Feb 18, 2020 at 15:12
  • yep that is exactly right. If it still throws the 500 error, just wrap it in the try/catch and see if you can grab more info on the issue. Commented Feb 18, 2020 at 15:28
0

At first glance I can see a syntax error here (if it is like that in your cloud page):

 %%[
     /*Page 2 AMPscript - validation */

 %%[

You are openging another ampscript block without closing one.
However you should definately go with Gortoningtons approach in the future. Its almost impossible to code without that ssjs try catch block.

You must log in to answer this question.

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