title: Set default value of a field in the SOLine grid
body: <p>I created a custom field as a combobox on the Stock Item page, InventoryItem.UsrLeadTime, as follows:</p>
  
  <pre><code>[PXDBString(10)]
  [PXUIField(DisplayName="Lead Time")]
  [PXStringList(new string[] { "4", "7", "10" },
  
    new string[] { "4", "7", "10" },
  
    MultiSelect = false, ExclusiveValues = false)]
  </code></pre>
  
  <p>I also created a custom field on the SO Order Entry SOLine grid as a combox, SOLine.UsrLeadTimeSOLine, as follows:</p>
  
  <pre><code>[PXDBString(10)]
  [PXUIField(DisplayName="Lead Time")]
  [PXStringList(new string[] { "4", "7", "10" },
  
    new string[] { "4", "7", "10" },
  
    MultiSelect = false, ExclusiveValues = false)]
  </code></pre>
  
  <p>I am trying to set the default value of the UsrLeadTimeSOLine on the SOLine grid to be the value specified by UsrLeadTime from Stock Items based on the InventoryID selected when entering a new line on a Sales Order.  My code on the SOOrderEntry graph extension is as follows:</p>
  
  <pre><code>    protected virtual void SOLine_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
     {
         SOLine row = (SOLine)e.Row;
  
          using (new PXConnectionScope())
              {
              InventoryItem invleadTime = PXSelect&lt;InventoryItem,
              Where&lt;InventoryItem.inventoryID, Equal&lt;Required&lt;InventoryItem.inventoryID&gt;&gt;&gt;&gt;
              .Select(Base, row.InventoryID);
  
  
              if (invleadTime != null)
                    {
                      PX.Objects.IN.InventoryItemExt ext = PXCache&lt;InventoryItem&gt;.GetExtension&lt;InventoryItemExt&gt;(invleadTime);
                      sender.SetValue&lt;SOLineExt.usrLeadTimeSOLine&gt;             (row,ext.UsrLeadTime);
                     Base.Transactions.Update(row);
                      //SOLineExt rowExt = sender.GetExtension&lt;SOLineExt&gt;(row);
                      //rowExt.UsrLeadTimeSOLine = ext.UsrLeadTime;
                      //Base.Transactions.Update(row);
                     }
              else
               {
                   throw new PXException("invleadTime is null");
                 }
  
                }
  
        }
  </code></pre>
  
  <p>I tossed in the else throw exception as an after thought to insure my query was returning a result.  Without the else the code compiles correctly and the Sales Order page runs correctly, but the lead time value in the SOLine grid, SOLine.UsrLeadTimeSOLine, remains blank when you add a new line and choose an inventoryID even though the InventoryID has a value for lead time, InventoryItem.UsrLeadTime, on the Stock Items page. </p>
  
  <p>After I added the else throw exception, when you add a new Sales Order Line, the exception appears immediately and declares invleadTime to be null as expected.  Selecting an InventoryID causes the Lead Time value of the SOLine grid, SOLine.UsrLeadTimeSOLine, to be set equal to the Lead Time value from the Stock Items page, InventoryItem.UsrLeadTime. In other words, it works as expected. </p>
  
  <p>Also, during Save it creates a new blank line and throws an error about a required field being blank.  Delete the blank line and it saves fine.
  I am not much interested in the behavior of the page with the throw exception included other than the fact that the code seems to work in so far as setting my value as I wish when the throw exception is included.</p>
  
  <p>Can anyone suggest a modification to my code without the else throw that will cause it to correctly set the value of SOLine.UsrLeadTimeSOLine to be equal to InventoryItem.UsrLeadTime.
  Thanks</p>