If statement both true and false for same item

Describe the issue/error/question

a mysql query is performed. The IF node checks whether the ouput contains ‘error’ key-value pair. (if not empty). The result is both false and true even though ‘execute once’ is enabled

What is the error message (if any)?

n/a

Please share the workflow

(Select the nodes and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow respectively)
{
  "meta": {
    "instanceId": "f683212333b2b3d67d8731ecb37a5c2770b18016c107263ea7213119c03068ef"
  },
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "/v1/gxsessions",
        "responseMode": "responseNode",
        "options": {
          "rawBody": false
        }
      },
      "id": "5c52d05d-8f97-42ce-a832-cbb097ea029a",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        -100,
        340
      ],
      "webhookId": "ddad8189-da17-4a39-813f-ab8cc83d1983",
      "notesInFlow": true,
      "notes": "receive POST /v1/gxsessions"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"session_id\" : \"{{$node[\"Webhook\"].json[\"body\"][\"session_id\"]}}\", \"result_code\" : 4001 }",
        "options": {
          "responseCode": 500
        }
      },
      "id": "331aeac1-cb1b-4b04-9e07-6873ca8e7277",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        900,
        80
      ],
      "alwaysOutputData": true,
      "executeOnce": true,
      "notesInFlow": true,
      "continueOnFail": true,
      "notes": "return error response"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=insert\ninto pcrfmgmt.gxsessions\n(\nsession_id ,\nframed_ipv6_prefix,\nframed_ip_address,\ncalled_station_id,\nsubscription_id_data_0,\nsubscription_id_data_1,\n3gpp_sgsn_mcc_mnc,\ncc_request_type,\ncc_request_number,\norigin_host,\norigin_realm,\ndestination_host,\ndestination_realm,\nauth_application_id,\nsupported_features_list_id,\nsupported_features_list_flags,\nbearer_usage,\norigin_state_id,\nnetwork_request_support,\nip_can_type,\nrat_type,\nuser_equipment_info_type,\nuser_equipment_info_value,\nqos_information_qos_class_identifier,\nqos_information_max_requested_bandwidth_ul,\nqos_information_max_requested_bandwidth_dl,\nqos_information_guaranteed_bitrate_ul,\nqos_information_guaranteed_bitrate_dl,\nqos_information_bearer_identifier,\nqos_information_apn_aggregate_max_bitrate_ul,\nqos_information_apn_aggregate_max_bitrate_dl,\ndefault_eps_bearer_qos_qos_class_identifier,\ndefault_eps_bearer_qos_arp_priority_level,\ndefault_eps_bearer_qos_arp_pre_emption_capability,\ndefault_eps_bearer_qos_arp_pre_emption_vulnerability,\nan_gw_address,\n3gpp_user_location_info_tai,\n3gpp_user_location_info_ecgi,\n3gpp_ms_timezone,\nonline,\naccess_network_charging_address,\naccess_network_charging_identifier_gx_value,\n3gpp_charging_characteristics\n)\nvalues\n(\n'{{$json[\"body\"][\"session_id\"]}}',\n'{{$json[\"body\"][\"framed_ipv6_prefix\"]}}',\n'{{$json[\"body\"][\"framed_ip_address\"]}}',\n'{{$json[\"body\"][\"called_station_id\"]}}',\n'{{$json[\"body\"][\"subscription_id_data_0\"]}}',\n'{{$json[\"body\"][\"subscription_id_data_1\"]}}',\n'{{$json[\"body\"][\"3gpp_sgsn_mcc_mnc\"]}}',\n'{{$json[\"body\"][\"cc_request_type\"]}}',\n'{{$json[\"body\"][\"cc_request_number\"]}}',\n'{{$json[\"body\"][\"origin_host\"]}}',\n'{{$json[\"body\"][\"origin_realm\"]}}',\n'{{$json[\"body\"][\"destination_host\"]}}',\n'{{$json[\"body\"][\"destination_realm\"]}}',\n'{{$json[\"body\"][\"auth_application_id\"]}}',\n'{{$json[\"body\"][\"supported_features_list_id\"]}}',\n'{{$json[\"body\"][\"supported_features_list_flags\"]}}',\n'{{$json[\"body\"][\"bearer_usage\"]}}',\n'{{$json[\"body\"][\"origin_state_id\"]}}',\n'{{$json[\"body\"][\"network_request_support\"]}}',\n'{{$json[\"body\"][\"ip_can_type\"]}}',\n'{{$json[\"body\"][\"rat_type\"]}}',\n'{{$json[\"body\"][\"user_equipment_info_type\"]}}',\n'{{$json[\"body\"][\"user_equipment_info_value\"]}}',\n'{{$json[\"body\"][\"qos_information_qos_class_identifier\"]}}',\n'{{$json[\"body\"][\"qos_information_max_requested_bandwidth_ul\"]}}',\n'{{$json[\"body\"][\"qos_information_max_requested_bandwidth_dl\"]}}',\n'{{$json[\"body\"][\"qos_information_guaranteed_bitrate_ul\"]}}',\n'{{$json[\"body\"][\"qos_information_guaranteed_bitrate_dl\"]}}',\n'{{$json[\"body\"][\"qos_information_bearer_identifier\"]}}',\n'{{$json[\"body\"][\"qos_information_apn_aggregate_max_bitrate_ul\"]}}',\n'{{$json[\"body\"][\"qos_information_apn_aggregate_max_bitrate_dl\"]}}',\n'{{$json[\"body\"][\"default_eps_bearer_qos_qos_class_identifier\"]}}',\n'{{$json[\"body\"][\"default_eps_bearer_qos_arp_priority_level\"]}}',\n'{{$json[\"body\"][\"default_eps_bearer_qos_arp_pre_emption_capability\"]}}',\n'{{$json[\"body\"][\"default_eps_bearer_qos_arp_pre_emption_vulnerability\"]}}',\n'{{$json[\"body\"][\"an_gw_address\"]}}',\n'{{$json[\"body\"][\"3gpp_user_location_info_tai\"]}}',\n'{{$json[\"body\"][\"3gpp_user_location_info_ecgi\"]}}',\n'{{$json[\"body\"][\"3gpp_ms_timezone\"]}}',\n'{{$json[\"body\"][\"online\"]}}',\n'{{$json[\"body\"][\"access_network_charging_address\"]}}',\n'{{$json[\"body\"][\"access_network_charging_identifier_gx_value\"]}}',\n'{{$json[\"body\"][\"3gpp_charging_characteristics\"]}}'\n)"
      },
      "id": "10444feb-008f-4a0d-a79a-7ccd27695d13",
      "name": "MySQL",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 1,
      "position": [
        240,
        340
      ],
      "alwaysOutputData": true,
      "notesInFlow": true,
      "credentials": {
        "mySql": {
          "id": "1",
          "name": "MySQL account"
        }
      },
      "continueOnFail": true,
      "notes": "store Gx session"
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"error\"]}}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "id": "8bc94f53-1c4a-44a5-b32b-9c651a0f26ad",
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        480,
        340
      ],
      "alwaysOutputData": true,
      "executeOnce": true,
      "notesInFlow": true,
      "continueOnFail": true,
      "notes": "if not stored"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"session_id\" : \"{{$node[\"Webhook\"].json[\"body\"][\"session_id\"]}}\", \"result_code\" : 2001 }",
        "options": {
          "responseCode": 200
        }
      },
      "id": "290a37da-2673-4acd-8fc5-fc622a6780e0",
      "name": "Respond to Webhook1",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        900,
        400
      ],
      "alwaysOutputData": true,
      "executeOnce": true,
      "notesInFlow": true,
      "continueOnFail": true,
      "notes": "return success"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond to Webhook1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

## Share the output returned by the last node
<!-- If you need help with transforming the data, please also share the expected output -->

## Information on your n8n setup
- **n8n version:**0.202.1

- **Database you're using (default: SQLite):**sqlite
- **Running n8n with the execution process [own(default), main]:**
- **Running n8n via [Docker, npm, n8n.cloud, desktop app]:**docker

Hi @sl-tobe

You have always output data turned on, I think this will always put something in the true branch. is it correct that the true branch has an empty item?

yes it is true

so set that option to false and you are done :wink:

1 Like

yes it is fixed, thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.