Skip to content

Instantly share code, notes, and snippets.

@wvpv
Last active May 9, 2022 16:07
Show Gist options
  • Save wvpv/a85098b5dc15b6b07912 to your computer and use it in GitHub Desktop.
Save wvpv/a85098b5dc15b6b07912 to your computer and use it in GitHub Desktop.
SFMC Check Subscriber List Members
%%[
var @isASubscriber, @sk, @row, @status, @listID
set @isASubscriber = 0
/* ListID can be found in the List's Properties tab */
set @listID = "111111"
/* Retrieve the SubscriberKey/EmailAddress */
/* via URL Parameter: */
/* set @sk = RequestParameter("sk") */
/* via Profile Attribute: */
/* set @sk = AttributeValue("_subscriberkey") */
/* for testing: */
set @sk = "[email protected]"
set @rr = CreateObject("RetrieveRequest")
SetObjectProperty(@rr,"ObjectType","ListSubscriber")
AddObjectArrayItem(@rr,"Properties","ListID")
AddObjectAttayItem(@rr,"Properties","Status")
set @sfp1 = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp1,"Property","SubscriberKey")
SetObjectProperty(@sfp1,"SimpleOperator","equals")
AddObjectArrayItem(@sfp1,"Value",@sk)
set @sfp2 = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp2,"Property","ListID")
SetObjectProperty(@sfp2,"SimpleOperator","equals")
AddObjectArrayItem(@sfp2,"Value",@listID)
set @cfp = CreateObject("ComplexFilterPart")
SetObjectProperty(@cfp,"LeftOperand", @sfp1)
SetObjectProperty(@cfp,"LogicalOperator", "AND")
SetObjectProperty(@cfp,"RightOperand", @sfp2)
SetObjectProperty(@rr,"Filter",@cfp)
set @ListSubObj = InvokeRetrieve(@rr,@rrStatus,@rrRequestID)
if rowCount(@ListSubObj) > 0 then
set @row = row(@ListSubObj, 1)
set @status = field(@row,'Status')
if @status == "Active" then
set @isASubscriber = 1
endif
endif
]%%
isASubscriber: %%=v(@isASubscriber)=%%
<br>sk: %%=v(@sk)=%%
<br>rrStatus: %%=v(@rrStatus)=%%
<br>status: %%=v(@status)=%%
@Tovelainen
Copy link

Hi,
your code snippet here has been a huge help for me, thanks so much :-)
However, I am just receving the All Subscribers status when using @status above.
If a subscriber is added to a list and after that unsubscribes, the @status is always "Active" even though I can see that status is set to Unsubscribe in the system.
Do you have any idea on how to get status for a specific list?

Thanks and best regards

@bmoothedan
Copy link

I have the same problem as Tovelainen, I always get the Active status for the user. In the list I can see an Unscuscribed value. Any help on this one is most appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment