added get_final_parent function to support parent id dropdown selection