Skip to content

Instantly share code, notes, and snippets.

@jacksonpchen
Last active December 2, 2020 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacksonpchen/815830817f2e281d9d403fbd59172aff to your computer and use it in GitHub Desktop.
Save jacksonpchen/815830817f2e281d9d403fbd59172aff to your computer and use it in GitHub Desktop.
Add to Publication List
/*
AMPscript.com
*/
SET @rr = CreateObject("RetrieveRequest")
SetObjectProperty(@rr, "ObjectType", "List")
AddObjectArrayItem(@rr,"Properties","ListName")
AddObjectArrayItem(@rr,"Properties","ID")
SET @sfp = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp, "Property", "ListName")
SetObjectProperty(@sfp, "SimpleOperator", "equals")
AddObjectArrayItem(@sfp, "Value",@PublicationType)
SetObjectProperty(@rr, "Filter", @sfp)
SET @Sub = InvokeRetrieve(@rr)
Set @ListID = "xxxx"
SET @ll_sub = CreateObject("Subscriber")
SetObjectProperty(@ll_sub, "EmailAddress", @EmailAddress)
SetObjectProperty(@ll_sub, "SubscriberKey", @subKey)
set @subscription = CreateObject("SubscriberList")
SetObjectProperty( @subscription, "ID",@ListID)
SetObjectProperty( @subscription, "IDSpecified", "true" )
SetObjectProperty( @subscription, "Status", "Active" )
SetObjectProperty( @subscription, "StatusSpecified", "true" )
AddObjectArrayItem( @ll_sub, "Lists", @subscription )
SET @ll_statusCode = InvokeUpdate(@ll_sub, @ll_statusMsg, @errorCode)
IF @ll_statusCode != "OK" THEN
RaiseError(@ll_statusMsg, 0, @ll_statusCode, @errorCode)
ENDIF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment