How to write data to a custom field I had another question at Save data to custom field columns using entity_metadata_wrapper and a similar issue at https://drupal.org/node/2110161, which nobody has been able to figure out yet.

Since entity_metadata_wrapper isn't working for writing custom field values, how can I do this manually?  I've tried the following code, but when I view the node afterwards, the field value is blank.

$fieldname = 'field_device_id';
    $query = db_insert('field_data_' . $fieldname)
        -&gt;fields(array(
          'entity_type' =&gt; 'node',
          'bundle' =&gt; 'equipment',
          'entity_id' =&gt; $new_ent-&gt;getIdentifier(),
          'language' =&gt; 'und',
          'delta' =&gt; 0,
          $fieldname . '_esn_hex' =&gt; isset($conversion_values['ESN_HEX']) ? $conversion_values['ESN_HEX'] : NULL,
          $fieldname . '_esn_dec' =&gt; isset($conversion_values['ESN_DEC']) ? $conversion_values['ESN_DEC'] : NULL,
          $fieldname . '_meid_hex' =&gt; isset($conversion_values['MEID_HEX']) ? $conversion_values['MEID_HEX'] : NULL,
          $fieldname . '_meid_dec' =&gt; isset($conversion_values['MEID_DEC']) ? $conversion_values['MEID_DEC'] : NULL,
          $fieldname . '_imei_hex' =&gt; isset($conversion_values['IMEI_HEX']) ? $conversion_values['IMEI_HEX'] : NULL,
          $fieldname . '_imei_dec' =&gt; isset($conversion_values['IMEI_DEC']) ? $conversion_values['IMEI_DEC'] : NULL,
          $fieldname . '_iccid_hex' =&gt; isset($conversion_values['ICCID_HEX']) ? $conversion_values['ICCID_HEX'] : NULL,
          $fieldname . '_iccid_dec' =&gt; isset($conversion_values['ICCID_DEC']) ? $conversion_values['ICCID_DEC'] : NULL,
          $fieldname . '_raw_id' =&gt; $id,
        ))
        -&gt;execute();
  }


This code runs after a submit handler passes in a device id that a user has entered, and converts it to several different formats, which are available in $conversion_values.

There has got to be a way to programmatically write values to custom field columns defined in hook_schema.
As far as the procedural method is concerned, you would use exactly the same method for a custom field as you would a contrib/core field.

Core field:

$node-&gt;body[LANGUAGE_NONE][0] = array(
  'value' = '&lt;p&gt;Some body text&lt;/p&gt;',
  'format' =&gt; 'full_html',
);


Your custom field:

$node-&gt;field_whatever[LANGUAGE_NONE][0] = array(
  'esn_hex' =&gt; $some_val,
  'esn_dec' =&gt; $some_other_val,
  // etc...
);


To persist changes to both, use node_save() (or entity_save(), or whataver helper method the entity you're using provides).

node_save($node);


That's all you need to do. Manipulating the field tables manually is not recommended, as you bypass a lot of hooks that need to run, cache management, etc.

To use custom fields with an EntityMetadataWrapper, you need to go a bit further and describe the field and its columns to the entity module.

This involves adding property_type and property_callbacks to your field definition in hook_field_info(), and providing appropriate callbacks for those. There's a bit more information in this post