I'm pretty new to AmpScript and SF in general so hoping that this is something simple.

I’m getting the following error:


An error occurred when attempting to execute an UPSERTDATA function call. See inner exception for details. UPSERTDATA Function is not valid in content. This function is only allowed in a non batch context. Function: UPSERTDATA("GPR_EnrolmentAgreement_052017", 1, "EmailAddress", @EmailAddress, "processed", "1")



The UPSERTDATA function is called within a for loop like so



for @i = 1 to @rowCount do


var @AccountNameOfCDPNumber, @Title, @LastName, @FirstName, @HomeAddress1, @HomeAddress2,@HomeAddress3, @HomePostCode, @HomeCountry, @CompanyName, @CompanyAddress1, @CompanyAddress2, @CompanyAddress3, @CompanyPostCode, @CompanyCountry, @DOB, @DriverLicenceNumber, @DriverLicenceIssueDate, @DriverLicenceExpiryDate, @IssuingAuthority, @MobileTelephone,@EmailAddress, @USA_LDW, @USA_LIS, @USA_PAI_PEC, @CAN_LDW, @CAN_PAI_PEC, @USA_CarPref, @CAN_CarPref, @EMEA_SC, @EMEA_CDW, @EMEA_TP, @EMEA_PAI_PEC, @AUS_MaxCover, @AUS_AER, @NZ_AER, @NZ_PAI_PEC, @NZ_PEC, @EMEA_CarPref, @AUZNZ_CarPref, @GPR_Points, @GPR_FrequentTravellerNumber, @ContactPref, @Signature, @Date, @RentalTerms, @createdAt, @emailOptIn, @postOptIn, @smsOptIn, @TermsAndConditions, @HertzCDPNumber, @ThirdPartyMarketingOptIn, @costCentre


Set @row = Row(@rows,@i)

set @AccountNameOfCDPNumber = Field(@row,"AccountNameOfCDPNumber")

set @Title = Field(@row,"Title")

set @costCentre = Field(@row,"costCentre")

set @LastName = Field(@row,"LastName")

set @FirstName = Field(@row,"FirstName")

set @HomeAddress1 = Field(@row,"HomeAddress1")

set @HomeAddress2 = Field(@row,"HomeAddress2")

set @HomeAddress3 = Field(@row,"HomeAddress3")

set @HomePostCode = Field(@row,"HomePostCode")

set @HomeCountry = Field(@row,"HomeCountry")

set @DOB = Field(@row, "DOB")

set @CompanyName = Field(@row,"CompanyName")

set @CompanyAddress1 = Field(@row,"CompanyAddress1")

set @CompanyAddress2 = Field(@row,"CompanyAddress2")

set @CompanyAddress3 = Field(@row,"CompanyAddress3")

set @CompanyPostCode = Field(@row,"CompanyPostCode")

set @CompanyCountry = Field(@row,"CompanyCountry")

set @DriverLicenceNumber = Field(@row,"DriverLicenceNumber")

set @DriverLicenceIssueDate = Field(@row,"DriverLicenceIssueDate")

set @DriverLicenceExpiryDate = Field(@row,"DriverLicenceExpiryDate")

set @IssuingAuthority = Field(@row,"IssuingAuthority")

set @MobileTelephone = Field(@row,"MobileTelephone")

set @EmailAddress = Field(@row,"EmailAddress")

set @USA_LDW = Field(@row,"USA-LDW")

set @USA_LIS = Field(@row,"USA-LIS")

set @USA_PAI_PEC = Field(@row,"USA-PAI_PEC")

set @CAN_LDW = Field(@row,"CAN-LDW")

set @CAN_PAI_PEC = Field(@row,"CAN-PAI_PEC")

set @USA_CarPref = Field(@row,"USA-CarPref")

set @CAN_CarPref = Field(@row,"CAN-CarPref")

set @EMEA_SC = Field(@row,"EMEA-SC")

set @EMEA_CDW = Field(@row,"EMEA-CDW")

set @EMEA_TP = Field(@row,"EMEA-TP")

set @EMEA_PAI_PEC = Field(@row,"EMEA-PAI_PEC")

set @AUS_MaxCover = Field(@row,"AUS-MaxCover")

set @AUS_AER = Field(@row,"AUS-AER")

set @NZ_AER = Field(@row,"NZ-AER")

set @NZ_PAI_PEC = Field(@row,"NZ-PAI_PEC")

set @NZ_PEC = Field(@row,"NZ-PEC")

set @EMEA_CarPref = Field(@row,"EMEA-CarPref")

set @AUZNZ_CarPref = Field(@row,"AUZNZ-CarPref")

set @GPR_Points = Field(@row,"GPR-Points")

set @GPR_FrequentTravellerNumber = Field(@row,"GPR-FrequentTravellerNumber")

set @ContactPref = Field(@row,"ContactPref")

set @Signature = Field(@row,"Signature")

set @Date = Field(@row,"Date")

set @RentalTerms = Field(@row,"RentalTerms")

set @createdAt = Field(@row,"createdAt")

set @emailOptIn = Field(@row,"emailOptIn")

set @postOptIn = Field(@row,"postOptIn")

set @smsOptIn = Field(@row,"smsOptIn")

set @TermsAndConditions = Field(@row,"TermsAndConditions")

set @HertzCDPNumber = Field(@row,"HertzCDPNumber")

set @ThirdPartyMarketingOptIn = Field(@row,"ThirdPartyMarketingOptIn")



<td> %%=v(@HertzCDPNumber)=%% </td>

<td> %%=v(@AccountNameOfCDPNumber)=%% </td>

<td> %%=v(@costCentre)=%% </td>

<td> %%=v(@Title)=%% </td>

<td> %%=v(@LastName)=%% </td>

<td> %%=v(@FirstName)=%% </td>

<td> %%=v(@HomeAddress1)=%% </td>

<td> %%=v(@HomeAddress2)=%% </td>

<td> %%=v(@HomeAddress3)=%% </td>

<td> %%=v(@HomePostCode)=%% </td>

<td> %%=v(@HomeCountry)=%% </td>

<td> %%=v(@CompanyName)=%% </td>

<td> %%=v(@CompanyAddress1)=%% </td>

<td> %%=v(@CompanyAddress2)=%% </td>

<td> %%=v(@CompanyAddress3)=%% </td>

<td> %%=v(@CompanyPostCode)=%% </td>

<td> %%=v(@CompanyCountry)=%% </td>

<td> %%=FormatDate(@DOB,"MM/dd/yyyy")=%% </td>

<td> %%=v(@DriverLicenceNumber)=%% </td>

<td> %%=v(@DriverLicenceIssueDate)=%% </td>

<td> %%=v(@DriverLicenceExpiryDate)=%% </td>

<td> %%=v(@IssuingAuthority)=%% </td>

<td> %%=v(@MobileTelephone)=%% </td>

<td> %%=v(@EmailAddress)=%% </td>

<td> %%=v(@USA_LDW)=%% </td>

<td> %%=v(@USA_LIS)=%% </td>

<td> %%=v(@USA_PAI_PEC)=%% </td>

<td> %%=v(@CAN_LDW)=%% </td>

<td> %%=v(@CAN_PAI_PEC)=%% </td>

<td> %%=v(@USA_CarPref)=%% </td>

<td> %%=v(@CAN_CarPref)=%% </td>

<td> %%=v(@EMEA_SC)=%% </td>

<td> %%=v(@EMEA_CDW)=%% </td>

<td> %%=v(@EMEA_TP)=%% </td>

<td> %%=v(@EMEA_PAI_PEC)=%% </td>

<td> %%=v(@AUS_MaxCover)=%% </td>

<td> %%=v(@AUS_AER)=%% </td>

<td> %%=v(@NZ_AER)=%% </td>

<td> %%=v(@NZ_PAI_PEC)=%% </td>

<td> %%=v(@NZ_PEC)=%% </td>

<td> %%=v(@EMEA_CarPref)=%% </td>

<td> %%=v(@AUZNZ_CarPref)=%% </td>

<td> %%=v(@GPR_Points)=%% </td>

<td> %%=v(@GPR_FrequentTravellerNumber)=%% </td>

<td> %%=v(@ContactPref)=%% </td>

<td> %%=v(@Signature)=%% </td>

<td> %%=v(@Date)=%% </td>

<td> %%=v(@RentalTerms)=%% </td>

<td> %%=v(@createdAt)=%% </td>

<td> %%=v(@emailOptIn)=%% </td>

<td> %%=v(@postOptIn)=%% </td>

<td> %%=v(@smsOptIn)=%% </td>

<td> %%=v(@TermsAndConditions)=%% </td>





UPSERTDATA("GPR_EnrolmentAgreement_052017", 1, "EmailAddress", @EmailAddress, "processed", "1")

next @i ]%%

This code is being called within a scheduled email in Journey Builder


UpsertData is not used in emails. You need to use UpsertDE(). It is a limitation of the function, both are built out identically though so just changing the function should work.

| improve this answer | |

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.