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
endif
]%%
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?