The node_save() function is far easier to use and much more reliable. For node_save() you only need to know how to construct the node and every field is more or less the same: $node-&gt;FIELD_NAME[0][&#39;value&#39;], and &#39;value&#39; is the value that is stored in the database (the actual column names vary from one field to another, so you still need to know what they are). When you use drupal_execute you have to construct the node as it has been re-organized by all the field widgets, which requires understanding exactly what each widget looks like and what values it expects where. Some widgets (like optionwidgets and date widgets) are extremely complex and the data used on the node form looks totally different than the data that ultimately gets stored in the database. So you have to pre-process your data into whatever the widget expects.<br>
<br>The biggest problem is a long-running core bug (that may or may not have ever gotten fixed) that kept validation hooks from firing if you do drupal_execute() on multiple nodes in a single pass, as when you are migrating or importing data. That means that any massaging that might be done by the widgets during validation also does not get done and those types of fields are totally broken. Date fields and nodereference fields are two that have created lots of problems.<br>
<br>The only thing you lose by using node_save() is that it does not do validation, but the bug means it doesn&#39;t get done reliably anyway. It would be far easier to do your own data validation before you import and then do a simple node_save() to store it.<br>
<br>Karen<br><br><div class="gmail_quote">On Fri, Jul 29, 2011 at 7:57 PM, Emma Irwin <span dir="ltr">&lt;<a href="mailto:emma.irwin@gmail.com">emma.irwin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I&#39;ve used node_save without having to worry about defaults for irrelevant fields. Worked fine for CCK for me<br>
Personally, I think that your alternate solution &amp; function goes too far into a zone of complexity that you&#39;ll have more bugs as a result. I would also feel for any developer that comes after you and has to maintain that code :/<br>

<br>
Sent from my iPhone<br>
<div><div></div><div class="h5"><br>
On Jul 29, 2011, at 12:21 PM, &quot;David Cohen&quot; &lt;<a href="mailto:drupal@dave-cohen.com">drupal@dave-cohen.com</a>&gt; wrote:<br>
<br>
&gt; I&#39;m trying import some data from a user&#39;s Facebook profile into Drupal.<br>
&gt; The site in question has a lot of moving parts: Content Profile, CCK,<br>
&gt; Drupal for Facebook.<br>
&gt;<br>
&gt; I&#39;d like to query facebook for info about the user, then create or<br>
&gt; update a node with the data.  The node contains a lot of fields, and I&#39;m<br>
&gt; only interested in updating 1 or 2 (or 3 or 4) of them.<br>
&gt;<br>
&gt; My preference is to use drupal_execute() to create/update the profile<br>
&gt; node.  To do this, I have to fill out a $form_state[&#39;values&#39;] array.<br>
&gt; I&#39;ve tested this and noticed that if I leave out the values for any<br>
&gt; field in the node, that field will be reset to blank.  In other words my<br>
&gt; code needs to fill out values for all fields.  But to do so essentially<br>
&gt; prevents anyone from adding more fields via CCK.  The code would need to<br>
&gt; be updated for every change to the content type, which is too onerous.<br>
&gt;<br>
&gt; There are posts on <a href="http://drupal.org" target="_blank">drupal.org</a> describing this same problem, and<br>
&gt; suggesting using node_save() instead of drupal_execute() for this<br>
&gt; purpose.  What do the experts on this list recommend, drupal_execute()<br>
&gt; or node_save()?<br>
&gt;<br>
&gt; I had the thought that during hook_form_alter(), I could scan the form<br>
&gt; for all #default_values, and use them to populate the<br>
&gt; $form_state[&#39;values&#39;].  A function able to do that would, it seems to<br>
&gt; me, make drupal_execute() much easier to use.  That code would have to<br>
&gt; navigate the entire $form tree (at least all element children).  And<br>
&gt; would have to be smart about where #tree is true in order to get all the<br>
&gt; #default_values into the right $form_state[&#39;values&#39;].  Has anyone<br>
&gt; attempted such a thing?<br>
&gt;<br>
&gt; Thanks in advance, -Dave<br>
</div></div></blockquote></div><br>