If NID doesn't exist, save node? I'm using menu_get_object() to get the NID for a computed field. The problem is that on a node save, NID doesn't exist yet so the computed field produces an error. If I resave the node, everything works since now the NID exists for the computed field to refer to. How can I go about adding an IF statement that if NID doesn't exist, save the node?

$node = menu_get_object();
$assigned_uid = $node-&gt;field_agent[LANGUAGE_NONE][0]['target_id'];
$assigned_user = user_load($assigned_uid);
$percentage_split = $assigned_user-&gt;field_percentage_split[LANGUAGE_NONE][0]['value'];

$other_ins = (isset(field_get_items($entity_type, $entity, 'field_other_ins_')[0]) ? field_get_items($entity_type, $entity, 'field_other_ins_')[0]['value'] : 0);
$vb = (isset(field_get_items($entity_type, $entity, 'field_vb')[0]) ? field_get_items($entity_type, $entity, 'field_vb')[0]['value'] : 0);
$finder_s_fee = (isset(field_get_items($entity_type, $entity, 'field_finder_s_fee')[0]) ? field_get_items($entity_type, $entity, 'field_finder_s_fee')[0]['value'] : 0);
$broker_fee = (isset(field_get_items($entity_type, $entity, 'field_broker_fee')[0]) ? field_get_items($entity_type, $entity, 'field_broker_fee')[0]['value'] : 0);
$dlc_franchise_fee_hst = (isset(field_get_items($entity_type, $entity, 'field_franchise_fee_hst')[0]) ? field_get_items($entity_type, $entity, 'field_franchise_fee_hst')[0]['value'] : 0);

$value = (($other_ins + $vb + $finder_s_fee + $broker_fee) - $dlc_franchise_fee_hst ) * ($percentage_split/100);
$entity_field[0]['value'] = $value;
Try this at the top of your code:

global $node;
if (empty($node-&gt;nid)) {
  node_save($node);
}


Worked for me in D5 and D6.