--- title: "IF ELSE ENDIF" slug: "if-else-endif" updated: 2024-02-06T13:13:00Z published: 2024-02-06T13:13:00Z canonical: "docs.datajet.app/if-else-endif" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.datajet.app/llms.txt > Use this file to discover all available pages before exploring further. # IF ELSE ENDIF # IF…ELSE…ENDIF Allows conditional processing within a script. Accessed via Script Editor | Tools | IF ELSE ENDIF; 3 methods will be added to the script: - IF - ELSE - ENDIF NOTE: ELSE is optional and can be removed if not required ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/image-1669038403076.png) ## Helper Right-click in JSON to bring up evaluation options: - true - false - count field - count table - exists - empty ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/image-1697816071196.png) ```json { "method": "IF", "condition": "empty([table])", "project": "project" } ``` ```json { "method": "IF", "condition": "count([table.field],value)==?", "project": "project" } ``` ```json { "method": "IF", "condition": "count([table],*)==?", "project": "project" } ``` ```json { "method": "IF", "condition": "exists([table])", "project": "project" } ``` ```json { "method": "IF", "condition": "true", "project": "project" } ``` ```json { "method": "IF", "condition": "false", "project": "project" } ``` ## IF METHOD { "method": "IF", "condition": "", "project": "project" } Note: The IF method must be accompanied by an ENDIF method: { "method": "ENDIF", "project": "project" } It is possible to embed IF…ENDIF statements inside each other, but care must be taken to verify processing logic ### IF Conditions If the IF condition in a script evaluates as TRUE, then the methods inside the IF block will be executed. If the IF condition evaluates as FALSE then the block will be skipped and “skipped” will be displayed in the Scripting Panel Status column. #### Operators | **Operator** | **Meaning** | **Example** | | --- | --- | --- | | > | Greater than | "condition":"count([table.field],value)>0" | | < | Less Than | "condition":"count([table.field],value)<500" | | <= | Less than or equal to | "condition":"count([table.dataset1],1)<=10" | | >= | Greater than or equal to | "condition":"count([table.dataset1],null)<=50" | | == | Equal to | "condition":"count([table.field],value)==0" | | != | Not Equal To | "condition":"count([table.field],value)!=0" | MULTIPLE IF CONDITIONSNote:  version 6.2.5.1 and earlier DO NOT support compound IF conditions.    The || (OR) and && (AND) operators are not supported. #### Variable evaluation Script Variables (as defined using the DEFINES method) can be accessed within IF Conditions: { "method": "IF", "condition": "%MyVariable% != ActiveConfig", "project": "project" } { "method": "IF", "condition": "%HeaderRow%==5", "project": "project" } { "method": "IF", "condition": "%HeaderRow% > %StartRow%", "project": "project" } #### Distinct Value Counts for Fields To check counts for fields, use the following syntax: **count([table.fieldname],value) = XXX** For example: { "method": "IF", "condition": "count([customer.surname],smith)>20", "project": "project" } This condition will evaluate as true if there are more than 20 customers with the surname smith in the customer table. Note: The condition is case sensitive. Smith <> SMITH <> smith #### Evaluating the number of rows in a table To check counts for tables, specify the table and use the *value: **count([customer],*) > XXX** For example: { "method": "IF", "condition": "count([customer],*) > count([addresses],*) ", "project": "project" } This condition will evaluate as true if there are more records in the customer table than there are in the addresses table #### Dataset Counts To check counts for dataset, chose a dataset that has been saved to a table, and evaluate using the possible dataset values of: - null - 0 - 1 - Total **count([customer.dataset_segment],1) > XXX** For example: { "method": "IF", "condition": "count([customer.segment1],1)>1000", "project": "project" } This condition will evaluate as true if there are more than 1000 customers in segment 1. ## ELSE method Optional. Must be used in conjunction with both IF and ENDIF. If an ELSE method is encountered without a corresponding IF and ENDIF method, the script will generate a “Bad Condition” result, and the script will fail. The ELSE block is the code that is executed if the IF condition evaluates to FALSE. { "method": "ELSE", "project": "project" } ## ENDIF method Required. Must be used in conjunction with an IF method, and may also be preceeded by an ELSE method. { "method": "ENDIF", "project": "project" }