2

I have a Cloudpage that takes a value, processes some logic and sends an email. Unfortunately, it sends two emails when it should send one.

%%[
VAR @sfid, @contactId, @centre, @email, @subLanguage, @rowCountSub, @subscriptionRow, @subscription, @contact, @rowCountCon, @contactRow, @today, @valid, @emailaddr, @ts, @tsDef, @ts_sub, @ts_statusCode, @errorCode
SET @sfid = REQUESTPARAMETER('sk')
SET @exp = REQUESTPARAMETER('exp')
SET @today = FormatDate(Now(), 'yyyy-MM-dd')

SET @subscription = RetrieveSalesforceObjects('MAG_Subscription__c', 'MAG_Language__c, MAG_Centre__c, MAG_Contact__c', 'Id', '=', @sfid)
SET @rowCountSub = rowCount(@subscription)

IF @rowCountSub > 0 THEN

    SET @subscriptionRow = Row(@subscription, 1)
    SET @subLanguage = FIELD(@subscriptionRow, 'MAG_Language__c')
    SET @contactId = FIELD(@subscriptionRow, 'MAG_Contact__c')
    SET @centre = FIELD(@subscriptionRow, 'MAG_Centre__c')

ENDIF

SET @contact = RetrieveSalesforceObjects('Contact', 'Email', 'Id', '=', @contactId)
SET @rowCountCon = rowCount(@contact)

IF @rowCountCon > 0 THEN

    SET @contactRow = Row(@contact, 1)
    SET @email = FIELD(@contactRow, 'Email')

ENDIF


IF @exp > @today THEN
  SET @valid = TRUE
ELSE
 SET @valid = FALSE
ENDIF

IF @centre == 'Athens' and @valid == TRUE THEN
  SET @ts = CreateObject("TriggeredSend")
  SET @tsDef = CreateObject("TriggeredSendDefinition")

  SetObjectProperty(@tsDef, "CustomerKey", "test_trigger_2")
  SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)

  SET @ts_sub = CreateObject("Subscriber")
  SetObjectProperty(@ts_sub, "EmailAddress", @email)
  SetObjectProperty(@ts_sub, "SubscriberKey", @contactId)

  AddObjectArrayItem(@ts, "Subscribers", @ts_sub)

  SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)

ELSE
  SET @ts = CreateObject("TriggeredSend")
  SET @tsDef = CreateObject("TriggeredSendDefinition")

  SetObjectProperty(@tsDef, "CustomerKey", "test_trigger_1")
  SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)

  SET @ts_sub = CreateObject("Subscriber")
  SetObjectProperty(@ts_sub, "EmailAddress", @email)
  SetObjectProperty(@ts_sub, "SubscriberKey", @contactId)

  AddObjectArrayItem(@ts, "Subscribers", @ts_sub)

  SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)
ENDIF
]%%

No idea why but any help would be appreciated.

7
  • Are you adding contacts to a triggered send data extension?
    – 0xsegfault
    Dec 11, 2018 at 21:26
  • The triggered email send set up includes a data extension, which is being updated every time an email is sent.
    – neo2049
    Dec 11, 2018 at 22:08
  • Thanks . did you create this data extension from a template?
    – 0xsegfault
    Dec 12, 2018 at 4:04
  • Yes. template is a triggered email send template.
    – neo2049
    Dec 12, 2018 at 9:31
  • The the problem. The template will send emails automatically so you don’t need and use that bit of code you would just need to add them to the data extension. An alternative would be to use a normal de to send this
    – 0xsegfault
    Dec 12, 2018 at 9:41

0

You must log in to answer this question.

Browse other questions tagged .