1

I create a cloudpage with some checkboxes that reference a some Data Extension. Example image attached.

My attempted was use DeleteData in Ampscript with the syntax below:

Where Bike is my checkbox:

IF NOT EMPTY(@Bike) THEN
InsertData('Bike_DE','FirstName',@firstname,'LastName',@lastname,'Email',@email,'Telefone',@telefone,'CPF',@cpf)
ENDIF

IF EMPTY(@Bike) THEN
DeleteData('Bike_DE','FirstName',@firstname,'LastName',@lastname,'Email',@email,'Telefone',@telefone,'CPF',@cpf)
ENDIF

The fields in syntax like 'firstname' and etc. I want to delete if the checkbox was not checked.

I hope that my explanation that good. If anyone know how to help me, thanks in advance.enter image description here

1 Answer 1

1


You can use the RequestParameter() AMPScript function to listen for sent values.
Assuming each CheckBox is separate (different "Name" values), you can listen for each CheckBox value and process accordingly.

HTML:

<input type="checkbox" name="Bike" value="1"> I have a bike
<input type="checkbox" name="Car" value="1"> I have a car

AMPScript:

IF EMPTY(RequestParameter('Bike')) THEN
//Do Delete Function
ELSE
//Do UpsertData Function
ENDIF

IF EMPTY(RequestParameter('Car')) THEN
//Do Delete Function
ELSE
//Do UpsertData Function
ENDIF

UpsertData() will Insert or Update depending on existing records in the data extension. This way you can update the "subscribeDate" to the last time they submitted their preferences.
If you don't want to Upsert, you could use a RowCount() check on the target preference DE to see if a row already exists, then Update or Insert accordingly.

Note that when using CheckBoxes - unchecked values are NOT submitted in the Post Payload.
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox

3
  • Hi @CameronRobert. So thanks for the help, the code it's working fine. I did what you writed, but now i have another issue. If the record already exists in Data Extension and the Submit Button is clicked appears a error and the data does not insert. Example: the user in first moment is subscribed in Bike_DE, in secondo moment the user entry in DE and is marked the Bike_De and the Car_De, the erros appears and the records not inserted. I tried to use UpdateData, but the record does not inserted. Commented Mar 27, 2019 at 19:35
  • Hey Joao, you can try use the UpsertData() function: developer.salesforce.com/docs/… I have updated my response to include this information Commented Mar 28, 2019 at 6:43
  • Thanks, @Cameron. The code works! If you can, you know a way to 'prepopulate' the checkbox if the email already in the DE. I know the fields with the RequestParameter Commented Apr 1, 2019 at 18:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .