Body: <p>I've got the beginnings of a simple plugin to track views of an article page, just an entry with custom fields including 'dataViews' used below.</p>
  
  <p>Within Twig:</p>
  
  <pre><code>{% do craft.demoPlugin.incrementView(entry) %}
  </code></pre>
  
  <p>Variable above set with:</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  class DemoPluginVariable
  {
      /**
       * Increment count
       *
       * @param EntryModel $entry
       */
      public function incrementView(EntryModel $entry)
      {
          craft()-&gt;demoPlugin-&gt;incrementView($entry);
      }
  }
  </code></pre>
  
  <p>Here's the service code which picks up the</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  
  class DemoPluginService extends BaseApplicationComponent
  {
      /**
       * Increment view count
       *
       * @param EntryModel $entry
       */
      public function incrementView(EntryModel $entry)
      {
          $entry-&gt;setContentFromPost([
              'dataViews' =&gt; 1234,
          ]);
  
  
          $success = craft()-&gt;entries-&gt;saveEntry($entry);
          Craft::dd($success);
      }
  }
  </code></pre>
  
  <p>The above fails when passed an entry, with $success reporting false. Logging the error this is due to other fields on the entry being required and not passed through.</p>
  
  <p>Could anyone point me in the direction for updating just one field within a record?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-12T22:36:22.847Z
Comments.Text: Instead of `setContentFromPost`, try using `$entry->dataViews = 1234;`.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-13T08:22:53.983Z
Comments.Text: Must admit I've tried that as well Brad, drawing a bit of blank to be honest.
Comments.UserDisplayName: Chris Southam
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-13T12:17:31.553Z
Comments.Text: Have you see this? https://github.com/putyourlightson/craft-entry-count
Comments.UserDisplayName: Oli
Tags: <plugin-development><entry><entrymodel>
Title: Updating a single custom field within an Entry
ThreadText: # Updating a single custom field within an Entry
  
  (Asked by: username_0 on 2015-11-12)
  
  I've got the beginnings of a simple plugin to track views of an article page, just an entry with custom fields including 'dataViews' used below.
  
  Within Twig:
  
  ```
  {% do craft.demoPlugin.incrementView(entry) %}
  
  ```
  
  Variable above set with:
  
  ```
  <?php
  namespace Craft;
  
  class DemoPluginVariable
  {
      /**
       * Increment count
       *
       * @param EntryModel $entry
       */
      public function incrementView(EntryModel $entry)
      {
          craft()->demoPlugin->incrementView($entry);
      }
  }
  
  ```
  
  Here's the service code which picks up the
  
  ```
  <?php
  namespace Craft;
  
  class DemoPluginService extends BaseApplicationComponent
  {
      /**
       * Increment view count
       *
       * @param EntryModel $entry
       */
      public function incrementView(EntryModel $entry)
      {
          $entry->setContentFromPost([
              'dataViews' => 1234,
          ]);
  
          $success = craft()->entries->saveEntry($entry);
          Craft::dd($success);
      }
  }
  
  ```
  
  The above fails when passed an entry, with $success reporting false. Logging the error this is due to other fields on the entry being required and not passed through.
  
  Could anyone point me in the direction for updating just one field within a record?
  
  **Tags:** plugin-development, entry, entrymodel
  
  > **Comments:**
  > **username_1**: Instead of `setContentFromPost`, try using `$entry->dataViews = 1234;`.  
  > **username_0**: Must admit I've tried that as well username_1, drawing a bit of blank to be honest.  
  > **username_2**: Have you see this? https://github.com/putyourlightson/craft-entry-count  
  
  ---
  
  ## 0 answers
  
  