Migrate Module and AddressField Locality/City Lookup in PrepareRow Fails I'm running a migration to move volunteers from a csv file to drupal.  I have written the following code.

&lt;?php
/**
    * @file
    * Migration for Volunteer File 
*/

ini_set('auto_detect_line_endings', TRUE);

class VolunteerMigration extends Migration {

public function __construct($arguments) {
    parent::__construct($arguments);

    $this-&gt;description = t('Imports Volunteers from CSV file ');

    // Create a source object
    $columns = array(
        0 =&gt; array('pkid', 'PKID'),
        1 =&gt; array('fname', 'First Name'),
        2 =&gt; array('lname', 'Last Name'),
        3 =&gt; array('email','Email'),
        5 =&gt; array('dayphone','DayPhone'),
        6 =&gt; array('eveningphone','EveningPhone'),
        7 =&gt; array('address','Address'),
        8 =&gt; array('city', 'City'),
        9 =&gt; array('state','State'),
        10 =&gt; array('postalcode','zip'),
        11 =&gt; array('occupation','Occupation'),
        12 =&gt; array('interests','Interests'),
        13 =&gt; array('created','Timestamp'),
    );
    $address_arguments = array(
        'first_name' =&gt; array('source_field' =&gt; 'fname'),
        'last_name' =&gt; array('source_field' =&gt; 'lname'),
        'thoroughfare' =&gt; array('source_field' =&gt; 'address'),
        'locality' =&gt; array('source_field' =&gt; 'city'),
        'administrative_area' =&gt; array('source_field'=&gt;'state'),
        'postal_code' =&gt; array('source_field' =&gt; 'postalcode'),
    );
    $this-&gt;source = new MigrateSourceCSV('/mnt/www/cylindrical/theoregonproject.com/data/drvollist.csv', $columns, array('header_rows' =&gt; 1));

    // Create a destination object
    $this-&gt;destination = new MigrateDestinationNode('volunteers');

    // Create a map
    $this-&gt;map = new MigrateSQLMap(
        $this-&gt;machineName,
        array(
            'pkid' =&gt; array(
                'type' =&gt; 'int',
                'unsigned' =&gt; TRUE,
                'not null' =&gt; TRUE,
            ),
        ),
        MigrateDestinationNode::getKeySchema(),
        'campaign_migration'
    );

    // Create Mappings
    $this-&gt;addFieldMapping('title', NULL)-&gt;DefaultValue('Volunteer');
    $this-&gt;addFieldMapping('field_volunteer_address')
        -&gt;arguments($address_arguments);
    $this-&gt;addFieldMapping('field_volunteer_id', 'pkid');
    $this-&gt;addFieldMapping('field_email', 'email');
    $this-&gt;addFieldMapping('field_dayphone', 'dayphone');
    $this-&gt;addFieldMapping('field_eveningphone', 'eveningphone');
    $this-&gt;addFieldMapping('field_occupation', 'occupation');
    $this-&gt;addFieldMapping('field_interests', 'interests')
            -&gt;separator(',');
    $this-&gt;addFieldMapping('created','created');

}

public function prepareRow($row) {

    if ( $row-&gt;zip ) { 
        $row-&gt;city = zipcity($row-&gt;zip);
    }
}

public function zipcity($zip) {
    $ch = curl_init('http://ziptasticapi.com/' . $zip);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    $result = curl_exec($ch);
    curl_close($ch);

    $json = json_decode($result,true);

    return $json['city'];
}
}
?&gt;


I'm am using the ziptastic api to fill in the cities using the zipcode.  Running the migration returns all except the address portion of the migration.  The zipcity function works as expected (returns city given a zipcode) but none of the address arguments are migrated.

I have adapted this code from a previous and successful migration minus the preparerow / zipcity additions.

Mark
Found the issue.  When using the addressfield module, you should have field mappings that allow for preparerow to work.  I thought that the address_arguments array was enough to create the field maps.  Also I was using the csv column title 'Zip' instead of the the mapped field title 'postalcode'

Under my address field mapping I added the following code.

    $this-&gt;addFieldMapping(NULL, 'fname');
    $this-&gt;addFieldMapping(NULL, 'lname');
    $this-&gt;addFieldMapping(NULL, 'address');
    $this-&gt;addFieldMapping(NULL, 'city');
    $this-&gt;addFieldMapping(NULL, 'state');
    $this-&gt;addFieldMapping(NULL, 'postalcode'); 


I also moved the function zipcity to my helper function file to allow other migrations to use it if needed.

This post https://drupal.org/node/1326044 was key into figuring out the missing link.