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 Viacom Media.</strong>
<br>
<br>
<input type="radio" checked="checked" id="Unsubscribe" name="Unsubscribe" value="YES">
<strong>YES</strong>
<input type="radio" id="Unsubscribe" name="Unsubscribe" value="NO">
<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.
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"
"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!!
{}
tool in the editor (orCtrl-K
) to format your code inclusions. I've done that for you above.