I'm using "Log A Unsub Event" using ampsript in a cloud page to unsubscribe the subscriber in marketing cloud, also my Marketing cloud instance is a multi org enbled org.
When I'm unsubscribing the user using the "Log A Unsub Event" in ampscript, it also updates the "EmailOptOut" field in Sales cloud and updates it to true and we do not want this becuase we have multiple BU's connected to same Sales cloud environment.
I also tried updating the record back to false for "EmailOptOut" using "UpdateSalesforceSingleObject" for this field, but it did not work.
How can we prevent the "EmailOptOut" field update when we fire "Log A Unsub Event" using ampsript or re-update the "EmailOptOut" back to false when it is once updated by ""Log A Unsub Event" using ampsript.
Below mentioned is the code :-
<script runat="server">
Platform.Load("Core","1.1.1");
try{
</script>
%%[
/* SET @emailAddress = requestparameter("Email")
set @SubKey= requestparameter("SubKey")*/
set @SubKey= "00QsssasasEffffgea"
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)
*/
/* You must set ClientID when working with On Your Behalf accounts*/
var @lue_oyb
set @lue_oyb = CreateObject('ClientID')
SetObjectProperty(@lue_oyb, 'ID','232322323')
SetObjectProperty(@lue, 'Client', @lue_oyb)
SET @rowset = RetrieveSalesforceObjects('Lead', 'HasOptedOutOfEmail', 'Id', '=', '00QsssasasEffffgea')
set @numberOfRows = RowCount(RetrieveSalesforceObjects('Lead', 'Email', 'Id', '=', '00QsssasasEffffgea'))
set @HasOptedOutOfEmailValue = Field(Row(@rowset, 1), "HasOptedOutOfEmail")
SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)
SET @Response = Row(@lue_statusCode, 1)
SET @Status = Field(@Response,"StatusMessage")
SET @Error = Field(@Response,"ErrorCode")
SET @initialValue = Substring(@SubKey,1,3)
SET @DEName = AttributeValue("_DataSourceName")
SET @flag = "False"
If @HasOptedOutOfEmailValue =='true' THEN
SET @flag = 'true'
ELSEIf @HasOptedOutOfEmailValue =='false' THEN
SET @flag = 'false'
ENDIF
SET @PersonContactID = ""
SET @updateRecord =0
IF @initialValue == "003" THEN
set @AID = LookupRows("Accounts","PersonContactID",@SubKey)
set @row = row(@AID, 1)
set @PersonContactID = field(@row,"Id")
ENDIF
IF @initialValue == "003" THEN
SET @updateRecord = UpdateSingleSalesforceObject("Account",@PersonContactID,"MTI_Email_Opt_Out__c",1)
ELSEIF @initialValue == "00Q" THEN
SET @updateRecord = UpdateSingleSalesforceObject("Lead",@SubKey,"MTI_Email_Opt_Out__c",1)
ENDIF
UpdateSingleSalesforceObject("Lead",'00QsssasasEffffgea',"HasOptedOutOfEmail",@flag)
SET @rowset1 = RetrieveSalesforceObjects('Lead', 'HasOptedOutOfEmail', 'Id', '=', '00QsssasasEffffgea')
set @numberOfRows1 = RowCount(RetrieveSalesforceObjects('Lead', 'Email', 'Id', '=', '00QsssasasEffffgea'))
set @HasOptedOutOfEmailValue1 = Field(Row(@rowset1, 1), "HasOptedOutOfEmail")
]%%
<script runat="server">
}catch(e){
Write(Stringify(e));
}
</script>