title: Microsoft Dynamics CRM Plugin: Retrieve Attribute from Look Up Field
body: <p>im new in CRM. I have create two entity : Order and Product. On order entity there is look up field that fire to product entity. I try to get productquantity from product through look up field and paste it to a field within the order entity. Here is the code i tried: </p>
  
  <pre><code>if (context.InputParameters.Contains("Target") &amp;&amp; context.InputParameters["Target"] is Entity)
          {
              Entity entity = (Entity)context.InputParameters["Target"];
  
  
  
              if (entity.Attributes.Contains("new_productname"))
              {
                  Entity productreference = service.Retrieve("new_callistyproduct", ((EntityReference)entity["new_productname"]).Id, new ColumnSet(true));
  
                  if (productreference.Attributes.Contains("new_productquantity"))
                  {
                      if (entity.Attributes.Contains("new_numberofproduct"))
  
  
                         entity["new_numberofproduct"] = productreference.GetAttributeValue&lt;Decimal&gt;("new_productquantity");
  
                     else
  
                       entity.Attributes.Add("new_numberofproduct", productreference.GetAttributeValue&lt;Decimal&gt;("new_productquantity"));
  
  
  
                  }
  
              }
  
  
  
          }
  </code></pre>
  
  <p>I want this plugin work whenever i create a new record. So i register this plugin as Pre-create event. But, when i try to create a record. This plugin did't retrieve value from productquantity field. 
  So, i tried to run this plugin as Pre-Update event. On the record i've create before, i change the lookup value from product A to product B. And its work, the plugin retrieve a product quantity value from product B.</p>
  
  <p>The question is, what should i do if i want this plugin also work for pre-Create event. </p>
  
  <p>Thanks</p>