Return inserted serial from drupal_write_record I have a module which creates records in the db via drupal_write_record and this works perfectly. However I need to get the automatically assigned serial number for each record which is written into a variable. 

Does anyone know how I can achieve this and get the index #? 

I need the index variable to use in another table to create the reference...

Edit: Clives answer worked as below:

// Create object
$call = new stdClass;  
$call-&gt;uid = $user-&gt;uid;
$call-&gt;call_type = $call_type;
$call-&gt;cli = $cli;
$call-&gt;start_nid = NULL;
$call-&gt;timestamp = $timestamp;

// Insert call row in db  
drupal_write_record($table,$call);

// Test correct index
drupal_set_message($call-&gt;call_id);
drupal_write_record() populates the serial field of an object you pass to it automatically. So assuming you have a serial field in your table called id, if you run code like the following:

$record = new stdClass;
$record-&gt;title = 'Title';
$record-&gt;some_other_field = 'Something';

drupal_write_record('table_name', $record);


the $record object will be auto-populated with a member representing the serial column when the function returns. In this example you can access it with $record-&gt;id.