0

I have a form with a list of checkboxes and I want to upsert the ticked boxes to a DE in marketing cloud.

I have 2 problems. 1) the record in the DE is being created twice 2) the check boxes are not updating.

Here is the ampscript - i have xxed the redirect pages

%%[
IF RequestParameter("submitted") =='submitted' THEN

 SET @Salutation = RequestParameter("Salutation")  
 SET @PersonEmail = RequestParameter("PersonEmail")
 SET @FirstName = RequestParameter("FirstName")
 SET @LastName = RequestParameter("LastName")
 SET @Interest = RequestParameter("Interest")
 SET @Country = RequestParameter("Countries")
 SET @Region = RequestParameter("Regions")
 SET @SourceFrom = RequestParameter("ExactTarget Source Form")
 SET @DonorType = RequestParameter("Donor/Organisation Record Type")
 SET @Ownership = RequestParameter("Ownership")
 SET @rs= RetrieveSalesforceObjects('Account', 'Email_Address_Unique__c', 'Email_Address_Unique__c', '=', @PersonEmail)

/***Redirect for existing records or create new record in salesforce***/
IF @rs IS NOT NULL then Redirect("https://pub.s6.exacttarget.com/xxx") 
ELSE
SET @_SFobjid = CreateSalesforceObject("Account",7,"Salutation",@Salutation,"FirstName",@FirstName,"LastName",@LastName,"Email_Address_Unique__c",@PersonEmail,"RecordTypeId",@DonorType,"ExactTarget_Source_Form__pc",@SourceFrom,"OwnerId",@Ownership)
ENDIF

/***Set Record Type***/

if "Account" == "Contact" then SET @_SFtype = "Contact" endif
if "Account" == "Lead" then SET @_SFtype = "Lead" endif

/*** Retrieve the Contact ID, that was created in order to set subscriber key for triggered send ***/

Set @CreatedRecord = RetrieveSalesforceObjects('Account', 'Email_Address_Unique__c,PersonContactID', 'Email_Address_Unique__c', '=', @PersonEmail)

IF RowCount(@CreatedRecord) > 0  then
SET @selectedRecord = Row(@CreatedRecord,1)
SET @subKey = Field(@selectedRecord,'PersonContactID')
ENDIF

/***Set Marketing Cloud DE values***/

 SET @Interest_water = false
 SET @Interest_food = false
 SET @Interest_war = false
 SET @Interest_emergency = false
 SET @Interest_registration = false
 SET @Interest_shelter = false
 SET @Interest_education = false
 SET @Interest_medicine = false
 SET @Interest_repatriationresettlement = false
 SET @Interest_nopreference = false
 SET @country_syria = false
 SET @country_south_sudan = false
 SET @country_somalia = false
 SET @country_afghanistan = false
 SET @country_iraq = false
 SET @country_yemen = false
 SET @country_nopreference = false
 SET @region_africa = false
 SET @region_americas = false
 SET @region_asiaPacific = false
 SET @region_europe = false
 SET @region_middleeast = false
 SET @region_nopreference = false

 /*** Set interests ***/
 IF IndexOf(@interest,"water") > 0 THEN SET @Interest_Water = true ENDIF
 IF IndexOf(@interest,"food") > 0 THEN SET @Interest_Food = true ENDIF
 IF IndexOf(@interest,"war") > 0 THEN SET @Interest_War = true ENDIF
 IF IndexOf(@interest,"emergency") > 0 THEN SET @Interest_Emergency = true ENDIF
 IF IndexOf(@interest,"registration") > 0 THEN SET @Interest_Registration = true ENDIF
 IF IndexOf(@interest,"shelter") > 0 THEN SET @Interest_Shelter = true ENDIF
 IF IndexOf(@interest,"education") > 0 THEN SET @Interest_Education = true ENDIF
 IF IndexOf(@interest,"medicine") > 0 THEN SET @Interest_Medicine = true ENDIF
 IF IndexOf(@interest,"Voluntary repatriation/Resettlement") > 0 THEN SET @Interest_RepatriationResettlement = true ENDIF
 IF IndexOf(@interest,"no preference") > 0 THEN SET @Interest_NoPreference = true ENDIF

 /*** Set country ***/
 IF IndexOf(@country,"Syria") > 0 THEN SET @Country_Syria = true ENDIF
 IF IndexOf(@country,"South Sudan") > 0 THEN SET @Country_South_Sudan = true ENDIF
 IF IndexOf(@country,"Somalia") > 0 THEN SET @Country_Somalia = true ENDIF
 IF IndexOf(@country,"Afghanistan") > 0 THEN SET @Country_Afghanistan = true ENDIF
 IF IndexOf(@country,"Iraq") > 0 THEN SET @Country_Iraq = true ENDIF
 IF IndexOf(@country,"Yemen") > 0 THEN SET @Country_Yemen = true ENDIF
 IF IndexOf(@country,"No Preference") > 0 THEN SET @Country_NoPreference = true ENDIF

 /*** Set Region ***/
 IF IndexOf(@region,"Africa") > 0 THEN SET @Region_Africa = true ENDIF
 IF IndexOf(@region,"Americas") > 0 THEN SET @Region_Americas = true ENDIF
 IF IndexOf(@region,"Asia and the Pacific") > 0 THEN SET @Region_AsiaPacific = true ENDIF
 IF IndexOf(@region,"Europe") > 0 THEN SET @Region_Europe = true ENDIF
 IF IndexOf(@region,"Middle East and North") > 0 THEN SET @Region_MiddleEast = true ENDIF
 IF IndexOf(@region,"No Preference") > 0 THEN SET @Region_NoPreference = true ENDIF

UpsertData("HK_EN_eNEWS_Signup",1,"SubscriberKey",@SubKey,"EmailAddress",@PersonEmail,"Salutation",@salutation,"FirstName",@FirstName,"LastName",@LastName,"Interest_Water",@Interest_Water,"Interest_Food",@Interest_Food,"Interest_War",@Interest_War,"Interest_Emergency",@Interest_Emergency,"Interest_registration",@Interest_Registration,"Interest_Shelter",@Interest_Shelter,"Interest_Education",@Interest_Education,"Interest_Medicine",@Interest_Medicine,"Interest_RepatriationResettlement",@Interest_RepatriationResettlement,"Interest_NoPreference",@Interest_NoPreference,"Country_Syria",@Country_Syria,"Country_South_Sudan",@Country_South_Sudan,"Country_Somalia",@Country_Somalia,"Country_Afghanistan",@Country_Afghanistan,"Country_Iraq",@Country_Iraq,"Country_Yemen",@Country_Yemen,"Country_NoPreference",@Country_NoPreference,"Region_Africa",@Region_Africa,"Region_Americas",@Region_Americas,"Region_AsiaPacific",@Region_AsiaPacific,"Region_Europe",@Region_Europe,"Region_MiddleEast",@Region_MiddleEast,"Region_NoPreference",@Region_NoPreference)

 /*** Set Triggered Send Values ***/

 VAR @ts, @tsDef, @ts_sub, @ts_attr, @tsctr, @ts_subkey, @ts_statusCode, @ts_statusMsg, @errorCode

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

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

 SET @ts_sub = CreateObject("Subscriber")
 SetObjectProperty(@ts_sub, "EmailAddress", RequestParameter("PersonEmail"))

 IF NOT EMPTY(@subKey) THEN
 SetObjectProperty(@ts_sub, "SubscriberKey", @subKey)
 ELSE
 SetObjectProperty(@ts_sub, "SubscriberKey", RequestParameter("PersonEmail"))
 ENDIF

 IF NOT IsNull(@Country) THEN
 SET @ts_attr = CreateObject("Attribute")
 SetObjectProperty(@ts_attr, "Name", "Country")
 SetObjectProperty(@ts_attr, "Value", @Country)
 AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)
 ENDIF

 IF NOT IsNull(@FirstName) THEN
 SET @ts_attr = CreateObject("Attribute")
 SetObjectProperty(@ts_attr, "Name", "FirstName")
 SetObjectProperty(@ts_attr, "Value", @FirstName)
 AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)
 ENDIF

 IF NOT IsNull(@LastName) THEN
 SET @ts_attr = CreateObject("Attribute")
 SetObjectProperty(@ts_attr, "Name", "LastName")
 SetObjectProperty(@ts_attr, "Value", @LastName)
 AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)
 ENDIF

 IF NOT IsNull(@DonorType) THEN
 SET @ts_attr = CreateObject("Attribute")
 SetObjectProperty(@ts_attr, "Name", "RecordTypeId")
 SetObjectProperty(@ts_attr, "Value", @DonorType)
 AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)
 ENDIF

 IF NOT IsNull(@SourceFrom) THEN
 SET @ts_attr = CreateObject("Attribute")
 SetObjectProperty(@ts_attr, "Name", "Source")
 SetObjectProperty(@ts_attr, "Value", @SourceFrom)
 AddObjectArrayItem(@ts_sub, "Attributes", @ts_attr)
 ENDIF

AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)

IF @ts_statusCode != "OK" THEN
 RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode)
ENDIF

Redirect("https://pub.s6.exacttarget.com/xxx")
ENDIF
]%%
5
  • hi @Data_Kid - yes they can have more than one interest, there is a list of checkboxes on the form which are supposed to update a boolean field from false to true
    – Clare
    Jun 8, 2018 at 10:30
  • scratch the Caps theory just did a test and its fully case insensitive
    – 0xsegfault
    Jun 8, 2018 at 10:41
  • @interest variable is a header on the form itself, i will remove that and see it it helps
    – Clare
    Jun 8, 2018 at 10:49
  • or try printing it to see what its returning. same goes for coutries and the other check boxes
    – 0xsegfault
    Jun 8, 2018 at 10:52
  • as to why its upserting twice my only guess is that one of the redirects might be to the same page, so the upsert fires twice
    – 0xsegfault
    Jun 8, 2018 at 10:52

1 Answer 1

3

Reasons for interests not populating, does the form have a interest attribute?

Reasons for 2 inserts into DE - there is a upsert statement and a triggered send ampscript api call which will both add records to the same DE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.