This is what I have in the _cm_initialise() method of the parent entity in the POPUP2 task:
$pattern_id = getPatternId();
if (!preg_match('/order_id=/i', $where)) {
if (isset($GLOBALS['return_from'])) {
if ($GLOBALS['return_from'] == 'ord_order_header_p(popup1)') {
// nothing selected from popup screen, so exit now
scriptPrevious($GLOBALS['errors']);
} // if
} // if
if (preg_match('/popup2/i', $pattern_id)) {
// order_id has not been supplied yet, so get it now via a popup
scriptNext('ord_order_header_p(popup1)', $where);
} // if
} // if
It is expecting to find "order_id=...." in the $where string. If it isn't there it suspends the current task and executes the popup which will provide a value for order_id. If this popup is terminated without choosing a value then this task will quit and return to the task which called it.