-- SELECT * FROM adempiere.fnt_get_nodelevel(1000056, 1000002);
CREATE OR REPLACE FUNCTION fnt_get_nodelevel(p_node_id NUMERIC(10,0), p_tree_id NUMERIC(10,0))
RETURNS NUMERIC(10,0)
AS $$
DECLARE
v_node_level NUMERIC(10,0) DEFAULT 0;
v_parent_id NUMERIC(10,0);
v_node_id NUMERIC(10,0);
BEGIN
v_parent_id =
(
SELECT
tn.parent_id
FROM ad_treenode tn
WHERE tn.ad_tree_id = p_tree_id
AND node_id = p_node_id
);
v_node_id = v_parent_id;
IF(v_parent_id = 0)THEN
RETURN v_node_level;
END IF;
WHILE(v_parent_id > 0)LOOP
v_parent_id =
(
SELECT
tn.parent_id
FROM ad_treenode tn
WHERE tn.ad_tree_id = p_tree_id
AND tn.node_id = v_node_id
);
v_node_id = v_parent_id;
v_node_level = v_node_level + 1;
END LOOP;
RETURN v_node_level;
END;
$$ LANGUAGE plpgsql;
martes, 24 de agosto de 2021
Get Node Level from Some Tree in iDempiere
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario