0

I build a profile center using ampscript and cloudpage, I tried to update all subscribers status use below code but it did not update the subscriber's status at sfmc:


IF RequestParameter("submitted") == true AND RequestParameter("unsub") == true THEN

  /* update contact in Sales Cloud */
  SET @updateRecord = UpdateSingleSalesforceObject(
      "Contact", @contactId,
      "Newsletter__c", "false",
      "Events__c", "false",
      "Offers__c", "false",
      "HasOptedOutOfEmail", "true"
     )  
  
  /* log unsubscribe event to mark as unsubscribed in All Subscribers */
  SET @reason = "Unsubscribed through custom subscription center"

  SET @lue = CreateObject("ExecuteRequest")
  SETObjectProperty(@lue,"Name","LogUnsubEvent")

  SET @lue_prop = CreateObject("APIProperty")
  SETObjectProperty(@lue_prop, "Name", "SubscriberKey")
  SETObjectProperty(@lue_prop, "Value", @contactId)
  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)
1
  • Are you sure that the @contactId value was populated correctly?
    – Duc Le
    Commented Feb 7 at 6:24

1 Answer 1

0

Does the call to Sales Cloud work correctly?

Try wrapping your unsub code in to debug:

<script runat="server"> Platform.Load("Core","1.1.1"); try{ </script>

%%[AMPSCRIPT HERE]%%

<script runat="server"> }catch(e){ Write(Stringify(e)); } </script>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .