0

good day I'm trying to activate or deactivate some checkboxes according to some specific rules, when I do it with only one checkbox it works perfectly

<label class=""> <!--%%=v(@Checkbox_Sub_Salesforce)=%%-->
<label class="contenedor">
<input type="checkbox" class="todisablecy" 
%%[IF @variable == 1 OR
@variable == 6 OR 
@variable == 9 OR 
@variable == 11 OR 
@variable == 12 OR 
@variable == 14 OR 
@variable == 15 OR 
@variable == 16  THEN]%%checked 
%%[ENDIF IF @variable == 2 OR @variable == 3 OR @variable ==  OR @variable == 5 OR @variable == 7 OR @variable == 8 OR @variable == 10 OR @variable == 13 THEN]%%disabled %%[ENDIF]%%>
<span class="checkmark"></span>
<span class="label-body">Autorizo terceros</span>
</label>
</label>

but when I try to code the others I get an error 500

<label class=""> <!--%%=v(@Checkbox_Sub_Salesforce)=%%-->
                      <label class="contenedor">
                        <input type="checkbox" class="todisablecy" %%[IF @variable == 1 OR @variable == 6 OR @variable == 9 OR @variable == 11 OR @variable == 12 OR @variable == 14 OR @variable == 15 OR @variable == 16  THEN]%%checked %%[ENDIF IF @variable == 2 OR @variable == 3 OR @variable ==  OR @variable == 5 OR @variable == 7 OR @variable == 8 OR @variable == 10 OR @variable == 13 THEN]%%disabled %%[ENDIF]%%>
                        <span class="checkmark"></span>
                        <span class="label-body">Autorizo terceros</span>
                      </label>
                     </label>

                     <label class=""> <!--%%=v(@Checkbox_Sub_Salesforce)=%%-->
                      <label class="contenedor">
                        <input type="checkbox" class="todisablecy" %%[IF @variable == 1 OR @variable == 4 OR @variable == 7 OR @variable == 10 OR @variable == 11 OR @variable == 13 OR @variable == 14 OR @variable == 16  THEN]%%checked %%[ENDIF IF @variable == 2 OR @variable == 3 OR @variable == 5 OR @variable == 6 OR @variable == 8 OR @variable == 9 OR @variable == 12 OR @variable == 15 THEN]%%disabled %%[ENDIF]%%>
                        <span class="checkmark"></span>
                        <span class="label-body">Autorizo sms</span>
                      </label>
                     </label>

                     <label class=""> <!--%%=v(@Checkbox_Sub_AppExchange)=%%-->
                      <label class="contenedor">
                        <input type="checkbox" class="todisablecy" %%[IF @variable == 1 OR @variable == 5 OR @variable == 8 OR @variable == 10 OR @variable == 12 OR @variable == 13 OR @variable == 15 OR @variable == 16  THEN]%%checked %%[ENDIF IF @variable == 2 OR @variable == 3 OR @variable == 4 OR @variable == 6 OR @variable == 7 OR @variable == 9 OR @variable == 11 OR @variable == 14 THEN]%%disabled %%[ENDIF]%%>
                        <span class="checkmark"></span>
                        <span class="label-body">Autorizo llamadas</span>
                      </label>
                     </label>

                     <label class=""> <!--%%=v(@Checkbox_Sub_Developer)=%%-->
                      <label class="contenedor">
                        <input type="checkbox" class="todisablecy" %%[IF @variable == 1 OR @variable == 3 OR @variable == 7 OR @variable == 8 OR @variable == 9 OR @variable == 10 OR @variable == 11 OR @variable == 12  THEN]%%checked %%[ENDIF IF @variable == 2 OR @variable == 4 OR @variable == 5 OR @variable == 6 OR @variable == 13 OR @variable == 14 OR @variable == 15 OR @variable == 16 THEN]%%disabled %%[ENDIF]%%>
                        <span class="checkmark"></span>
                        <span class="label-body">Autorizo E-mail</span>
                      </label>
                     </label>

0

2 things:

  1. You have a condition with an operator but no value in your 'first' section. This is likely causing your 500 error.
@variable == OR

inside:

<label class=""> <!--%%=v(@Checkbox_Sub_Salesforce)=%%-->
                      <label class="contenedor">
                        <input type="checkbox" class="todisablecy" %%[IF @variable == 1 OR @variable == 6 OR @variable == 9 OR @variable == 11 OR @variable == 12 OR @variable == 14 OR @variable == 15 OR @variable == 16  THEN]%%checked %%[ENDIF IF @variable == 2 OR @variable == 3 OR @variable ==  OR @variable == 5 OR @variable == 7 OR @variable == 8 OR @variable == 10 OR @variable == 13 THEN]%%disabled %%[ENDIF]%%>
                        <span class="checkmark"></span>
                        <span class="label-body">Autorizo terceros</span>
                      </label>
                     </label>
  1. I have a couple points of advice to help make your code a bit more efficient.

First, you do not need the second if statement. You can instead just use an ELSE statement since each of your conditions in the second if statement are just those that are not inside the first conditional. Like this:

<label class=""> <!--%%=v(@Checkbox_Sub_Salesforce)=%%-->
                      <label class="contenedor">
                        <input type="checkbox" class="todisablecy" %%[IF @variable == 1 OR @variable == 6 OR @variable == 9 OR @variable == 11 OR @variable == 12 OR @variable == 14 OR @variable == 15 OR @variable == 16  THEN]%%checked %%[ELSE]%%disabled %%[ENDIF]%%>
                        <span class="checkmark"></span>
                        <span class="label-body">Autorizo terceros</span>
                      </label>
                     </label>

Second, if I have a ton of conditions that would be better used as an 'in' statement (which is not available in AMPScript), I make my own duct tape version. I will create a string that holds all the values and I will make this into a modified pipe delimited list. You can then do an indexof to see if your value exists in it - you just add a pipe before and after the value.

Sample string:

SET @c1Str = "|1|6|9|11|12|14|15|16|"

Sample comparison:

Set @c1Index = IndexOf(@c1Str,CONCAT("|",@variable,"|")

Then use an inline IF (IIF) instead of the IF conditional in a block.

%%=IIF(@c1Index > 0,"checked","disabled")=%%

You can then put it all together like this:

%%[
SET @c1Str = "|1|6|9|11|12|14|15|16|
SET @c1Index = IndexOf(@c1Str,CONCAT("|",@variable,"|")
]%%
<label class=""> <!--%%=v(@Checkbox_Sub_Salesforce)=%%-->
                      <label class="contenedor">
                        <input type="checkbox" class="todisablecy" %%=IIF(@c1Index > 0,"checked","disabled")=%%>
                        <span class="checkmark"></span>
                        <span class="label-body">Autorizo terceros</span>
                      </label>
                     </label>

This is quite a bit more manageable and easier to maintain (at least in my opinion) way to handle large conditionals and I feel it actually winds up being more performant and efficient.

1
  • Good day, thanks for your help, the error was because it lacked that number in the IF condition, the tape is very good but as I am reading this information of a variable I will not be able to use it, Thanks for your help Jul 21 '20 at 16:04

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.