0

Our SFMC org is multi org enabled and one of the child BU's is integrated with a sales cloud sandbox. Being multi-org we have to build a custom pref center. I have created a one click unsubscribe SFMC cloud page form with HTML code and a another cloud page which acts as a processing cloud page. Below is the code. I'm testing this with doing test sends. First question --> is it ok to test with test sends or do I need to use guided send or JB sends? The unsubscribe link in the email is the following: <a href="%%=CloudPagesURL(255)=%%" alias="Unsubscribe">Unsubscribe</a>.

When I click on the unsubscribe link, my email gets populated in the email address field and the form loads appropriately but when I click submit for unsubscribe, the processing page (in ampscript) results in a "500 - Internal server error." My one click unsubscribe form has the form action as

What am I doing wrong and what am I missing ? The code for both the pages is below: (ignore the commented code in the html since the success, error & thank you pages are embedded in the Ampscript cloud page)


HTML one click unsubscribe code:

<form id="Gen_Unsubscribe" action="%%=CloudPagesURL(254,"sk",_subscriberKey)=%%" method="POST">
  <fieldset>
    <legend><strong>Unsubscribe</strong></legend> 
    <br><strong>Please unsubscribe me from all emails sent by &nbsp;Viacom Media.</strong>
    <br>
    <br>
    <input type="radio" checked="checked" id="Unsubscribe" name="Unsubscribe" value="YES">&nbsp; 
    <strong>YES</strong>&nbsp;
    <input type="radio" id="Unsubscribe" name="Unsubscribe" value="NO">&nbsp;
    <strong>NO</strong>
    <br>
    <br>           
    <b>Enter Email:
    </b>
    <br> 

   <p>
    <input type="text" maxlength="100" name="Email Address" id="Email Address" value="%%Email Address%%" size="30">     
    </p>

    <input type="hidden" name="jobid" id="jobid" value="%%jobid%%">
    <input type="hidden" name="listid" id="listid" value="%%listid%%"> 
    <input type="hidden" name="batchid" id="batchid" value="%%batchid%%">
    <input name="MID" type="hidden" value="100039762">

    <p>
    </p>
    <input id="form-submit-Unsubscribe" name="submit" type="submit" value="Submit">
    <p>
    </p>
  </fieldset>
</form>

Processing page Ampscript code:






<script runat="server" language="ampscript">
  %%[
/* Get id for URL */
SET @SfContactId = QueryParameter("sk")
SET @EmailAddress = RequestParameter("Email Address")
SET @Status = "OK"
/* Update Contact in SF */
 SET @Result = UpdateSingleSalesforceObject("Contact",@SfContactId,"Email", @EmailAddress)
/* Log Unsub Event */ 
IF RequestParameter("Unsubscribe") == 'YES' THEN
  /* Update ET unsub and log it for tracking */
  SET @jid = RequestParameter("jobid")
  SET @listid = RequestParameter("listid")
  SET @batchid = RequestParameter("batchid")
  SET @reason = "Cust Profile Center Unsubscribe"
  SET @lue = CreateObject("ExecuteRequest")
  SetObjectProperty(@lue,"Name","LogUnsubEvent")
                    SET @lue_prop = CreateObject("APIProperty")                 
  SetObjectProperty(@lue_prop, "Name", "SubscriberKey")
                    SetObjectProperty(@lue_prop, "Value", @SfContactId)
  AddObjectArrayItem(@lue, "Parameters", @lue_prop)
                     SET @lue_prop = CreateObject("APIProperty")
  SetObjectProperty(@lue_prop, "Name", "JobID")
                    SetObjectProperty(@lue_prop, "Value", @jid)
  AddObjectArrayItem(@lue, "Parameters", @lue_prop)
                     SET @lue_prop = CreateObject("APIProperty")
  SetObjectProperty(@lue_prop, "Name", "ListID")
                    SetObjectProperty(@lue_prop, "Value", @listid)
  AddObjectArrayItem(@lue, "Parameters", @lue_prop)
                     SET @lue_prop = CreateObject("APIProperty")
  SetObjectProperty(@lue_prop, "Name", "BatchID")
                    SetObjectProperty(@lue_prop, "Value", @batchid)
  AddObjectArrayItem(@lue, "Parameters", @lue_prop)
                     SET @lue_prop = CreateObject("APIProperty")
  SetObjectProperty(@lue_prop, "Name", "Reason")
                    SetObjectProperty(@lue_prop, "Value", @reason)
  AddObjectArrayItem(@lue, "Parameters", @lue_prop)
                     SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)
  SET @Response = Row(@lue_statusCode, 1)
                      SET @Status = Field(@Response,"StatusMessage")
  SET @Error = Field(@Response,"ErrorCode")
                     ENDIF
                     IF @Status == "Event Posted" AND @Result == "1" AND RequestParameter("Unsubscribe") == 'YES' THEN

                     OutputLine(Concat("Hi,", " ", @EmailAddress," ", "We are sad to see you go."))


                     ELSEIF @Status == "OK" AND @Result == "1" AND RequestParameter("Unsubscribe") == 'NO' THEN

                     OutputLine(Concat("Hi,", " ", @EmailAddress," ", "You have not been unsubscribed."))


                     ELSE


                     OutputLine(Concat("Hi,", " ", @EmailAddress," ", "There seems to be an error!"))


                     ENDIF

  ]%%
</script>



                     <p>
                     @SfContactId: %%=v(@SfContactId)=%% <br>
                     @EmailAddress: %%=v(@EmailAddress)=%% <br>
                     @Result: %%=v(@Result)=%% <br>
                     @Status: %%=v(@Status)=%% <br></p>

UPDATE: Hi Zuzanna & Cameron,

Thanks a lot for your help! Aplogies for the delayed response. I got busy with some personal stuff in the afternoon. So the good news is that I’m no longer getting a 500 error. I had logged a support case with sfmc and it seems it was my mistake that I was sending the test email to a lead id (starts with 00Q….) instead of a ontact id. Here’s what the support rep had to say and the error:

Comment: Hello Girish,

Thank you for your response!

I have reviewed the JobID's you provided and our error logs. I believe I see the issue that is occurring. I will provide the error I am seeing below:

"ExactTarget.OMM.FunctionExecutionException: Call to update the salesforceobject Contact ID = %%_subskriberkey%% failed! Error status code: MALFORMED_ID Error message: Contact ID: id value of incorrect type: %%_subskriberkey%% Error Code: UPDATESINGLESFOJBECT_FUNC_ERROR"

The Subscriber Key that is being sent to is 00Q0C000002HJPCUA4 and this appears to be a Lead ID as it starts with 00Q. Contact records begin with 003. Are you able to perform a test with a record that has a valid Contact ID starting with 003?

Please let me know if you have any questions about the information provided. If testing with a valid Contact ID fails I will send an invite that will allow you to schedule a GoToMeeting session to discuss further. I look forward to hearing from you!

So after I did an actual send (guided send ) to a contact id, the contact get’s unsubscribed. The problem now is the processing page is again giving a 500 error. I have reposted the code again on Stack Exchange. I tried as per your suggestion to replace my code with the below in the processing page, but in the page preview it does not display anything. Does Ampscript not render in cloud pages preview? Sorry to ask such basic q’s since I don’t code very frequently but it’s getting more and more important now. %%[ SET @SfContactId = QueryParameter("sk") SET @EmailAddress = RequestParameter("Email Address")]%% @SfContactId: %%=v(@SfContactId)=%%
@EmailAddress: %%=v(@EmailAddress)=%%
How do I display these?

UPDATE 2 : I was finally able to get together with SFMC support over a GTM call and troubleshoot the errors they can see at the backend. Following is a list just for reference:

1."ExceptionDetail="ExactTarget.OMM.InvalidScriptException: A server side script tag specifies a language of html that is not supported. The supported languages are javascript and ampscript"

2."ExactTarget.OMM.InvalidScriptException: An IF statement is not closed with the required ENDIF statement.

  1. Statement: IF RequestParameter("Unsubscribe") == 'YES' THEN ]%% /* Update ET unsub and log it for tracking */ SET @jid = RequestParameter("jobid") SET @listid = RequestParameter("listid") SET @batchid = RequestParameter("batchid") SET @reason = "Cust Profile Center Unsubscribe" SET @lue = CreateObj Error Code: OMM_IF_STMT_ERR"

  2. "ExactTarget.OMM.InvalidFunctionException: Invalid characters appear at the end of the parameter value Function Call: v(@Email Address) Parameter Value: @Email Invalid Character: A Error Code: OMM_FUNC_SYNTAX_ERR"

These errors are not visible to us on the browser as most of you know. All we see is a "500-Internal Server error....etc" After resolving the errors above the code is fully functional and working now. I have reposted the final code. In the actual email the unsubscribe link has the following cloudpages url. Make sure to use redirectTo function and uncheck "track clicks" in test sends and "uncheck track links" in guided sends when you send your emails during testing. Hope this helps! Thanks a lot Zuzanna & Cameron again for all your guidance and help!!

  • Please make sure to use the {} tool in the editor (or Ctrl-K) to format your code inclusions. I've done that for you above. – David Reed Dec 28 '19 at 21:24
  • Thanks David! I did that for the HTML & the ampscript main code but missed the cloudpagesURL pieces. Will keep that in mind for the future. – Girish Dec 28 '19 at 22:18
1

You’re most likely getting a 500 because the parameters are not passed correctly.

Try creating a test list and doing an actual send to that list.

Here are three things to try:

1. Make sure all parameters are passed.

As Cameron noted, you have a parameter in the processing page which is not getting passed, and this is most likely the source of the problem:

RequestParameter("Subaction")

To make it work, you need to include the parameter in the link in your first page:

%%=CloudPagesURL(254,"Subaction","unsub")=%%

Above is just hardcoded, so if they have a choice of subscribing/unsubscribing, pass the real parameter.

If they only have a choice to unsubscribe, I would strip this completely from the processing page:

/* Log Unsub Event */ 
 IF RequestParameter("Subaction") == 'unsub' THEN
 /* Update ET unsub and log it for tracking */

And strip the ENDIF at the end.

2. If you’re using the CloudPagesURL function, you don’t need to pass the personalization strings separately.

Change to the following in your processing page:

SET @SfContactId = RequestParameter("_subscriberkey")
SET @EmailAddress = RequestParameter("emailaddr")

You can try displaying the values on the page to see if they are passed correctly:

@SfContactId: %%=v(@SfContactId)=%% <br>
@EmailAddress: %%=v(@EmailAddress)=%%

3. Debug the Salesforce functions.

One last thing you can do is wrapping your script in a try/catch statement, to see if the Salesforce functions are causing any issues.

| improve this answer | |
1

You can test most parts of this code from a Test Send; however I recommend you do a full test using a Guided Send before deploying any Preference Page code - to ensure the unsubscribe tracking is working properly.

It looks like your Processing Page is referencing RequestParameter("Unsubscribe") == 'YES' however you don't have an named "Unsubscribe" on your first page.

Looking at your form, you could make the following changes:

<p>
<input name="SubAction" id="sub" type="radio" value="sub"> 
<label for="sub">Subscribe</label><br>
<input name="SubAction" id="unsub" checked="checked" type="radio" value="unsub"> 
<label for="unsub">Unsubscribe</label>
</p>

With the above code, the value RequestParameter("SubAction") can be either "sub" or "unsub".

From here you can change the code on your second page to:

/* Log Unsub Event */ 
 IF RequestParameter("SubAction") == 'unsub' THEN
/* Update ET unsub and log it for tracking */

Note that your processing page as no "Update" or "ReSubscribe" code; so you may want to remove this option for your subscribers to avoid confusion.

| improve this answer | |
  • Thanks for the help Cameron! I have made the code changes suggested by you and posted the new code. I'm still getting the 500 - internal server error once I click submit on the HTML form page which sends the respective parameters to the processing page. I have created a new html form page, so there may be some differences between the previous and the new code. – Girish Dec 29 '19 at 3:11
  • Hey Girish, I just noticed your processing page also references QueryParameter”SK”, while the submit form has called it “ETSubscriberKey”. Can you fix that and try again? – Cameron Robert Dec 29 '19 at 3:15
  • Hi Cameron, I have changed that already and posted the new code. The form itself is a bit changed now. – Girish Dec 29 '19 at 3:23
  • Hey Girish, I can see you’ve changed a few things. At this point I recommend reverting to the original unsubscribe AmpScript source code (or a verified version posted by another member of the community). Once you have that working, you can customise it as you need. As above, you can test using a Test Send; but make sure you do a full Guided Send test before deploying to your subscribers. – Cameron Robert Dec 29 '19 at 3:45
  • Thanks Cameron! I'll do that and let you know. – Girish Dec 29 '19 at 4:14

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.