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)
->fields(array(
'entity_type' => 'node',
'bundle' => 'equipment',
'entity_id' => $new_ent->getIdentifier(),
'language' => 'und',
'delta' => 0,
$fieldname . '_esn_hex' => isset($conversion_values['ESN_HEX']) ? $conversion_values['ESN_HEX'] : NULL,
$fieldname . '_esn_dec' => isset($conversion_values['ESN_DEC']) ? $conversion_values['ESN_DEC'] : NULL,
$fieldname . '_meid_hex' => isset($conversion_values['MEID_HEX']) ? $conversion_values['MEID_HEX'] : NULL,
$fieldname . '_meid_dec' => isset($conversion_values['MEID_DEC']) ? $conversion_values['MEID_DEC'] : NULL,
$fieldname . '_imei_hex' => isset($conversion_values['IMEI_HEX']) ? $conversion_values['IMEI_HEX'] : NULL,
$fieldname . '_imei_dec' => isset($conversion_values['IMEI_DEC']) ? $conversion_values['IMEI_DEC'] : NULL,
$fieldname . '_iccid_hex' => isset($conversion_values['ICCID_HEX']) ? $conversion_values['ICCID_HEX'] : NULL,
$fieldname . '_iccid_dec' => isset($conversion_values['ICCID_DEC']) ? $conversion_values['ICCID_DEC'] : NULL,
$fieldname . '_raw_id' => $id,
))
->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.