I am creating a custom subscription center and I have been able to include a subscriber to a publication list when they unsubscribe from it with an unsubscribe status. I need to ensure that when they re-subscribe to the publication list, they get removed from the list instead of changing the status to active. (We do not want them to get all emails for that publication, just the suitable emails.)
If they appear on the publication list they will be removed with the following code:
/* CHECK TO SEE IF THE SUBSCRIBER HAS SUBSCRIBED. IF SO, DELETE OFF PUBLICATION LIST IF THEY ARE IN THERE*/
IF (RequestParameter(@PublicationType)=="True" AND @SubscriberPublicationList == "N" AND @existPubList == "True") THEN
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 = Field(Row(@Sub,1),"ID")
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 = InvokeDelete(@ll_sub, @ll_statusMsg, @errorCode)
IF @ll_statusCode != "OK" THEN
RaiseError(@ll_statusMsg, 0, @ll_statusCode, @errorCode)
ENDIF
ENDIF
NEXT @cnt
ENDIF
When I run this and a person is not on the list to begin with, it will give me the following error:
Error code: 13007
Status Code: Error
NotOnList
That makes sense! My question is how do I check to see if the subscriber is on the list. Once I know this, I can update my if statement to only run when they were only in this list (@existpubList == "True"). I think This needs to be done with a simpleFilterPart but I don't understand objects enough to get it to work.
I appreciate any help with this. Many thanks!
Based on Timothy's suggestion, I have tried to use an InvokeRetrieve to find out if a subscriber key exists in the list but I can't seem to get it to work. I have written the code below:
/* USE LOOK UP TO FIND SUBSCRIBER KEY IN LIST USING SIMPLEFILTERPART AND COMPLEXFILTERPART*/
SET @rr8 = CreateObject("RetrieveRequest")
SetObjectProperty(@rr8, "ObjectType", "ListSubscriber")
AddObjectArrayItem(@rr8,"Properties","ListID")
AddObjectArrayItem(@rr8,"Properties","SubscriberKey")
SET @sfp8 = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp8, "Property", "ListID")
SetObjectProperty(@sfp8, "SimpleOperator", "equals")
AddObjectArrayItem(@sfp8, "Value",@ListID)
SET @sfp9 = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp9, "Property", "SubscriberKey")
SetObjectProperty(@sfp9, "SimpleOperator", "equals")
AddObjectArrayItem(@sfp9, "Value",@subKey)
Set @cf1 = CreateObject("ComplexFilterPart")
SetObjectProperty(@cf1,"LeftOperand",@sfp8)
SetObjectProperty(@cf1,"RightOperand",@sfp9)
SetObjectProperty(@cf1,"LogicalOperator","AND")
SetObjectProperty(@rr8, "Filter", @cf1)
SET @LookUpSub = InvokeRetrieve(@rr8)
SET @RowCountSub = Rowcount(@LookUpSub)
IF (RequestParameter(@PublicationType)=="True" AND @SubscriberPublicationList == "N" AND @RowCountSub > 0) THEN
I get the following error:
The function expresion is invalid. See inner exception for detail.
Script: AddObjectArrayItem(@sfp8, "Value",@ListID)
Index: 10928
ListID: 1317684.
Am I using the wrong object for this InvokeRetrieve?
Many thanks!