Step1:Code1 I am processing on click of a unsubscribe button with a checkbox.
Step 2: Code 2 processing the list for unsubscribing using amp script.
Step 3: Code 3 It is updating the object field in the sales cloud
Code 2 and Code 3 having the same URL Link and getting used in Code1 in the link. to process after unsubscribing.
I am not able to update the sales cloud filed dynamically from the marketing cloud using amp script on the landing page. but it is working for hardcoded values.
can anyone help to identify the reason?
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Opt-Out</title>
<link rel="stylesheet" href="https://pub.s11.exacttarget.com/1z****" type="text/css">
</head>
<script src="https://ajax.googleapis.com/a*****"></script>
<script>
$(document).ready(function () {
});
function myFunction() {
var checkBox = document.getElementById("myCheck");
if (checkBox.checked == true){
}
else {
event.preventDefault();
alert("Please confirm for Unsubscribe");
}
}
</script>
<body>
<form method="post" action="https://pub.s11.exacttarget.com/aiuot*****?jobid=%%jobid%%&listid=%%listid%%">
<div class="center">
<img class="image" src="https://image.s11.sfmc-content.com/lib/fe3815717564047b7c1270/m/1/15dd9635-fdd0-478b-9c36-fa.jpg" alt="MyCompany">
</div>
<h1 class="center">We're sorry to see you go!</h1><br/>
<div class="center">
<p id="paragraph"> You can use the button below to unsubscribe. </p></div>
<br/><br/>
<div class="center">
<input type="checkbox" id="myCheck"> Unsubscribe<br><br>
<input type="submit" class="button" value="unsubscribe" onclick="myFunction()">
<input type="hidden" id="SubKey" name="SubKey" value="%%_subscriberkey%%">
</form>
</body>
</html>
Code 2 to process code 1
%%[
/* SET @emailAddress = requestparameter("Email") */
set @SubKey= requestparameter("SubKey")
set @jid= requestparameter("jobid")
set @listid= requestparameter("listid")
SET @lue = CreateObject("ExecuteRequest")
SetObjectProperty(@lue,"Name","LogUnsubEvent")
SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "SubscriberKey")
SetObjectProperty(@lue_prop, "Value", @SubKey)
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_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)
SET @Response = Row(@lue_statusCode, 1)
SET @Status = Field(@Response,"StatusMessage")
SET @Error = Field(@Response,"ErrorCode")
]%%
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Processing-Page</title>
<link rel="stylesheet" href="https://pub.s11.exacttarget.com/1z3*****" type="text/css">
<style>
body {
background: #1F222E;
}
</style>
</head>
<body>
<div>
<h1 class="center" style="color:#ffffff; text-align:center">You were successfully unsubscribed.</h1>
<div>
</body>
</html>
Code 3 to process code 1
%%[
/* SET @emailAddress = requestparameter("Email") */
set @SubKey= requestparameter("SubKey")
set @jid= requestparameter("jobid")
set @listid= requestparameter("listid")
SET @lue = CreateObject("ExecuteRequest")
SetObjectProperty(@lue,"Name","LogUnsubEvent")
SET @lue_prop = CreateObject("APIProperty")
SetObjectProperty(@lue_prop, "Name", "SubscriberKey")
SetObjectProperty(@lue_prop, "Value", @SubKey)
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_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)
SET @Response = Row(@lue_statusCode, 1)
SET @Status = Field(@Response,"StatusMessage")
SET @Error = Field(@Response,"ErrorCode")
/* Set the HasOptedOutOfEmail box to FALSE in SF */
IF LENGTH(@SubKey) == 18 AND IndexOf(@SubKey, "@") == 0 THEN
/*SET @updateRecord = UpdateSingleSalesforceObject("Contact", @SubKey, "HasOptedOutOfEmail", 0)*/
/*SET @updateRecord = UpdateSingleSalesforceObject("Lead",@SubKey, 'Last Name','Test')*/
SET @updateRecord = UpdateSingleSalesforceObject('BUI__c', @SubKey, "Opt_Out__c","true")
SET @updateRecord = UpdateSingleSalesforceObject('BUI__c', @SubKey, "UpdatedName__c", "Updatename !!")
SET @updateRecord = UpdateSingleSalesforceObject("BUI__c", @SubKey, "Name", "works!!")
ENDIF
]%%
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Processing-Page</title>
<link rel="stylesheet" href="https://pub.s11.exacttarget.com/1z3****" type="text/css">
<style>
body {
background: #1F222E;
}
</style>
</head>
<body>
<div>
<h1 class="center" style="color:#ffffff; text-align:center">You were successfully unsubscribed.</h1>
<div>
</body>
</html>