I would like use AMPscript in an email to check whether the Subscriber Key already exists in the All Subscribers list at the time of sending an email.

Obviously, I'm counting on the AMPscript being evaluated first before creating a Subscriber Record at send time.

I've tried using the code below:

var @retrieveSubscriber, @retrieveSubscriberFilter, @subscriberRow, @thisSubscriber, @subscriberField, @abort, @requestId

set @retrieveSubscriber = CreateObject("RetrieveRequest")
    SetObjectProperty(@retrieveSubscriber, "ObjectType", "Subscriber")
    AddObjectArrayItem(@retrieveSubscriber, "Properties", "SubscriberKey")

    set @retrieveSubscriberFilter = CreateObject("SimpleFilterPart")
    SetObjectProperty(@retrieveSubscriberFilter, "Property", "SubscriberKey")
    SetObjectProperty(@retrieveSubscriberFilter, "SimpleOperator", "equals")
    AddObjectArrayItem(@retrieveSubscriberFilter, "Value", @subscriberEncodedsKey)

    SetObjectProperty(@retrieveSubscriber, "Filter", @retrieveSubscriberFilter)
    set @subscriberRow = InvokeRetrieve(@retrieveSubscriber, @requestId)
    set @thisSubscriber = row(@subscriberRow, 1)
    set @subscriberField = field(@thisSubscriber, "SubscriberKey")
    if @subscriberField == _subscriberkey then
        set @abort = true

I'm not sure if my code is correct or not but I receive the error:

An error occurred when attempting to evaluate a TreatAsContent function call. See inner exception for details. CreateObject Function is not valid in content. This function is only allowed in non sendable content. Function: CreateObject("RetrieveRequest")

Is there any way that I can check to see if a subscriber exists in the All Subscribers list within an email?

1 Answer 1


I don't think retrieves like this are allowed in emails. You could just use a lookup against the _Subscribers data view:


set @abort = false
set @sk = AttributeValue("_subscriberkey")

set @subscriberEncodedsKey = "[email protected]"
set @subscriberField = Lookup("ent._Subscribers", "SubscriberKey", "SubscriberKey", @subscriberEncodedsKey)

if @subscriberField == @sk then
    set @abort = true

<br>@sk: %%=v(@sk)=%%
<br>@subscriberField: %%=v(@subscriberField)=%%
<br>@abort: %%=v(@abort)=%%


@sk: [email protected] 
@subscriberField: [email protected] 
@abort: True 
  • Thanks Adam. I've tested this and it works correctly when previewing. however if I delete the subscribers from the All Subscribers list, when I send the email all subscribers are result as @abort: True. It appears that the Subscriber records are added before OMM evaluates the AMPscript, which is annoying. Can you think of a solution for this? Oct 25, 2016 at 17:15
  • HI Eliot, what if this code executed from an exclusion script? Will this evaluate before the record is added to all_subscribers? Oct 25, 2016 at 18:12
  • Hi @DavidDevoy, we're not using a Triggered Send for this however, I have come up with a solution; ultimately I want to ensure that the email address in the Triggered Send DE matches the Subscriber so I've used the AMPscript at gist.github.com/eliotharper/abaec0a7d378af4f2a9328b915dedb77 Oct 26, 2016 at 0:02
  • Thanks @AdamSpriggs, I've adapted your answer further but this certainly helped me in the right direction and your answer is technically correct although just be aware that OMM evaluates AMPscript after creating the subscriber. So I'm accepting your answer for the benefit of others. Oct 26, 2016 at 0:03

You must log in to answer this question.

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