title: CRM 2011 Field Security - data owner
body: <p>I have a custom field with security field enable also I configure security profile to allow manager to view/update this field but I also need to allow the owner of the entity field to view / update this field.
  Which in my case a field in account &amp; contact entity. </p>
  
  <p>I tried a couple of plugins found it on my search by I don't know how to get it work:</p>
  
  <pre class="lang-csh prettyprint-override"><code>public void ShareSecureFieldWithOwner(Entity record)
  {
  // Any method that helps you find the AttributeMetadata Id
  var attributeId = FindSecuredAttribute();
  
  if (attributeId != Guid.Empty)
  {
      var userAccess = new PrincipalObjectAttributeAccess
                           {
                               AttributeId = attributeId,
                               ObjectId = record.ToEntityReference(),
                               PrincipalId = record.OwnerId,
                               UpdateAccess = true,
                               ReadAccess = true
                           };
  
      context.AddObject(userAccess);
      context.SaveChanges();
  }
  }
  </code></pre>
  
  <p>Thanks in advance &amp; appreciate your support. </p>