We're building a custom preference center. The target DE that needs to be updated is in this case also used as sendable DE for testing purposes. The DE contains the following columns: externalID(text & Primary Key), Optin (boolean), Rating (text) EmailAddress(EmailAddress),FirstName (text) ,LastName (text). The issue is that even though MC recongizes that a contact has opt-in true and allows him to pass his decision and get to the validation/thank you landing page, the optin record in the target DE does NOT get updated.
Here's the case: On the first custom preference page built in Web Studio landing page (via Content Builder), here's the ampscript code:
%%[
VAR @externalID, @optin
set @externalID=RequestParameter('ExternalID')
set @rowsMaster=LookupRows("Test_DE_Company_and_Agency","ExternalID", @externalID)
IF RowCount(@rowsMaster)>0 THEN
SET @rowMaster=Row(@rowsMaster,1)
SET @Email=Field(@rowMaster,"EmailAddress")
ENDIF
SET @rows=LookupRows("Test_DE_Company_and_Agency","externalID", @externalID)
IF RowCount(@rows)>0 THEN
SET @row=Row(@rows,1)
SET @optin=Field(@row,"Optin")
ENDIF
]%%
In the html, we have
... the form tag:
%%[IF @optin==1 THEN ]%%
<label>
<input id="Optin" name="Optin" type="checkbox" checked="true" value="Optin" onclick="CheckUnSubscribe()"> I wish to receive communications by email from Company.
</label>
%%[ELSE]%%
<label>
<input id="Optin" name="Optin" type="checkbox" value="Optin" onclick="CheckUnSubscribe()"> I wish to receive communications by email from Company
</label>
%%[ENDIF]%%
</div>
<div class="btn-wrapper">
<button class="btn btn-default button" type="submit">Save your Preferences</button>
</div>
<input type="hidden" name="ExternalID" value="%%=v(@externalID)=%%">
</form>
On the second, confirmation page, we have the following Ampscript code:
%%[
set @externalID=RequestParameter('ExternalID')
set @checkboxO = RequestParameter('Optin')
set @currentTime = Now()
set @rowsMaster=LookupRows("Test_DE_Company_and_Agency","ExternalID", @externalID)
IF RowCount(@rowsMaster)>0 THEN
SET @rowMaster=Row(@rowsMaster,1)
SET @Email=Field(@rowMaster,"EmailAddress")
ENDIF
SET @ll_sub = CreateObject("Subscriber")
SetObjectProperty(@ll_sub,"EmailAddress", @Email)
SetObjectProperty(@ll_sub,"SubscriberKey", @externalID)
SET @client = CreateObject("ClientID")
SetObjectProperty(@client, "ID", 100008022)
SetObjectProperty(@client, "IDSpecified", "true")
SetObjectProperty(@ll_sub, "Client", @client)
Set @options = CreateObject("UpdateOptions")
Set @save = CreateObject("SaveOption")
SetObjectProperty(@save,"SaveAction","UpdateAdd")
SetObjectProperty(@save,"PropertyName","Status")
AddObjectArrayItem(@options,"SaveOptions", @save)
IF @checkboxO=="Optin" THEN
set @checkboxOval=1
SetObjectProperty(@ll_sub,"Status", "Active")
ELSE set @checkboxOval=0
SetObjectProperty(@ll_sub,"Status", "Unsubscribed")
ENDIF
updateDE("Test_DE_Company_and_Agency",1,"ExternalID", @externalID, "Optin",@checkboxOval)
]%%
In the html we have the "thank-you" text and the form validation:
<form action="%%=CloudPagesURL(1345)=%%" method="post">