Need help writing an AMPscript to create a campaignmember record AND also upsert a record to a data extension from an email send. This is the AMPscript I used.
%%[
var @contactId, @campaignId, @id, @contactRows, @limitRow
set @id = Id
set @campaignId = '70190000000sgS9'
set @contactRows = RetrieveSalesforceObjects('Account','PersonContactId','Id','=', @id)
set @limitRow = Row(@contactRows, 1)
set @contactId= Field(@limitRow, 'PersonContactId')
IF _messagecontext == "SEND" Then
CreateSalesforceObject(
'CampaignMember', 3,
'CampaignId',@campaignId,
'ContactId',@contactId,
'Status','Sent'
)
EndIF
]%%
When I perform a guided email send, the create campaign member record step works.
However, as I also want to create a send log Data extension and add subscribers that were sent the email to my data extension, I amended AMPscript to this and this causes the email send to fail.
%%[
var @contactId, @campaignId, @id, @contactRows, @limitRow,
set @id = Id
set @campaignId = '70190000000sgS9'
set @contactRows = RetrieveSalesforceObjects('Account', 'PersonContactId','Id', '=', @id)
set @limitRow = Row(@contactRows, 1)
set @contactId= Field(@limitRow, 'PersonContactId')
if_messagecontext != "SEND" then
CreateSalesforceObject(
'CampaignMember', 3,
'CampaignId',@campaignId,
'ContactId',@contactId,
'Status','Sent'
)
upsertDE
(
'EmailTrackingDE',1,
'SubscriberKey',_SubscriberKey,
'JobID',jobid,
'EmailName',emailname_,
'DateSent',NOW()
)
endif
]%%