data tree FEATURE lyd_has_when function
diff --git a/src/tree_data.h b/src/tree_data.h
index 4b3118d..0027364 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -88,6 +88,7 @@
  * - ::lyd_child_no_keys()
  * - ::lyd_parent()
  * - ::lyd_owner_module()
+ * - ::lyd_has_when()
  * - ::lyd_find_xpath()
  * - ::lyd_find_sibling_val()
  * - ::lyd_find_sibling_first()
@@ -771,6 +772,18 @@
 const struct lys_module *lyd_owner_module(const struct lyd_node *node);
 
 /**
+ * @brief Check whether this data node existence depends on any when conditions. This node's schema node and
+ * any direct parent choice and case schema nodes are also examined for when conditions.
+ *
+ * Be careful, this function is not recursive and checks only conditions that apply to this node directly.
+ * Meaning if there are any conditions associated with any parent of @p node, they are not returned.
+ *
+ * @param[in] node Data node to examine.
+ * @return When condition associated with the node, NULL if there is none.
+ */
+const struct lysc_when *lyd_has_when(const struct lyd_node *node);
+
+/**
  * @brief Check whether a node value equals to its default one.
  *
  * @param[in] node Term node to test.
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index 6979586..968dd87 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -154,6 +154,26 @@
     return schema->module;
 }
 
+API const struct lysc_when *
+lyd_has_when(const struct lyd_node *node)
+{
+    const struct lysc_node *schema;
+
+    if (!node || !node->schema) {
+        return NULL;
+    }
+
+    schema = node->schema;
+    do {
+        if (schema->when) {
+            return *schema->when;
+        }
+        schema = schema->parent;
+    } while (schema && (schema->nodetype & (LYS_CASE | LYS_CHOICE)));
+
+    return NULL;
+}
+
 const struct lys_module *
 lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module, const struct ly_ctx *ctx, uint32_t *i,
         struct lyd_node **first)