[SalesForce] use AmpScript to set Subscriber Status in Marketing Cloud

A prior developer built our microsite preference center using ampscript to grab user info from SalesForce and update the Contact/Lead info depending on the user's answers. In the case where a User unsubscribes, our CRM team would like the preference center to update the Subscriber's Status in Marketing Cloud as well. I know that their is an SSJS unsubscribe function that could be used for this, but the subscriber key variable – @subKey – is already set in AmpScript so I'm looking for an AmpScript solution or a way to set the subscriber key in SSJS. FYI – I'm new to SF, MC, and AmpScript.

Best Answer

There are two ways that you can approach this.

  1. Do it with Ampscript with InvokeUpdate API function. Check the Usage part on the documentation site, it's similiar to your use case, you just need to change status to 'Unsubscribed' from 'Active' and Save Options to 'Update' from 'UpdateAdd' to make it work
  2. Pass your variable from Ampscript to SSJS via SSJS Variable.GetValue() and make your unsubscribe in SSJS