Import a custom field type record and relate it to a node I've created a module for a custom field type which selects images from cloudinary. 

Is there a way to dynamically add entries as part of an import script? I've tried updating the database directly, but this is not ideal as it does not store any relations.

There is an answer for something similar, however I want to relate mine to an existing node. Is it possible with Node Export? If not, what am I doing wrong here:

My schema:

function cloudinary_field_schema() {    

    $columns = array(
        'publicID' =&gt; array('type' =&gt; 'varchar', 'length' =&gt; 255, 'not null' =&gt; FALSE),
        'title' =&gt; array('type' =&gt; 'varchar', 'length' =&gt; 255, 'not null' =&gt; FALSE),
        'caption' =&gt; array('type' =&gt; 'text', 'size' =&gt; 'big', 'not null' =&gt; FALSE),
        'url' =&gt; array('type' =&gt; 'varchar', 'length' =&gt; 255, 'not null' =&gt; FALSE),
        'credit' =&gt; array('type' =&gt; 'varchar', 'length' =&gt; 255, 'not null' =&gt; FALSE),
        'keywords' =&gt; array('type' =&gt; 'text', 'size' =&gt; 'big', 'not null' =&gt; FALSE),
        'description' =&gt; array('type' =&gt; 'text', 'size' =&gt; 'big', 'not null' =&gt; FALSE),
        'primaryImage' =&gt; array('type' =&gt; 'int', 'size' =&gt; 'tiny', 'not null' =&gt; FALSE)
    );

    return array(
        'columns' =&gt; $columns
    );    

}


My hook menu contains this:

function cloudinary_menu() {
    $items['cloudinary/add'] = array(
        'access callback' =&gt; TRUE,
        'page callback'  =&gt; 'add_image'
    );
}


And bad practice importer:

function add_image () {    

  $new_image = array();    

  //get post
  $entity_id = $_POST['entity_id'];
  $publicID = $_POST["publicID"];
  $url = $_POST["url"];
  $title = $_POST["title"];
  $caption  = $_POST["caption"];
  $description = $_POST["description"];
  $keywords = $_POST["keywords"];
  $credit = $_POST["credit"];
  $primaryImage = $_POST["primaryImage"];    

  //validate
  $entity_id = htmlspecialchars( $entity_id );
  $publicID = htmlspecialchars($publicID);
  $url = htmlspecialchars($url);
  $title = htmlspecialchars($title);
  $caption = htmlspecialchars($caption);
  $description = htmlspecialchars($description);
  $keywords = htmlspecialchars($keywords);
  $credit = htmlspecialchars($credit);
  $primaryImage = htmlspecialchars($primaryImage);    

  //add to new image
  $new_image["entity_id"] = intval($entity_id);
  $new_image["field_cloudinary_publicID"] = $publicID;
  $new_image["field_cloudinary_url"] = $url;
  $new_image["field_cloudinary_title"] = $title;
  $new_image["field_cloudinary_caption "] = $caption;
  $new_image["field_cloudinary_description"] = $description;
  $new_image["field_cloudinary_keywords"] = $keywords;
  $new_image["field_cloudinary_credit"] = $credit;
  $new_image["field_cloudinary_primaryImage"] = $primaryImage;
  $new_image["delta"] = 0;    

  //establish if this is a valid node using entity_id
  $result = db_query('SELECT * FROM {node} n WHERE n.nid = :nid', array(':nid' =&gt; $new_image["entity_id"]));    

  //if it is, update cloudinary
  if($result-&gt;rowCount() &gt; 0) {
    $r = $result-&gt;fetchAssoc();
    $new_image["entity_type"] = "node";
    $new_image["bundle"] = $r["type"];
    $insert_id = db_insert('field_data_field_cloudinary')-&gt;fields($new_image)-&gt;execute();
    drupal_json_output($insert_id);
  } else {
    drupal_json_output(false);
  }    

    drupal_exit();
}


I'm very new to Drupal so struggle a lot with this stuff! Any help greatly appreciated!
Just to double check: You have a content type with fields for your images from cloudinary, and you have nodes that already exist in your site that you need to get the data from Cloudinary into your node?

It looks like your looking up nodes through a query by the entity id (nid). Instead of doing that I would simply just load the node object by the node_load function (like node_load($entity_id). You should be able to then assign the value of cloudinary fields in the node (it's gonna be something like $node-&gt;FIELD_NAME['und'][0]['value']). Once you have all your custom fields inputed, just use node_save($node).