I am trying to set the value of TrackingCategory on an invoice Line Item. My code is as follows:
LineItem li = new LineItem();
li.LineAmount = inv.LineItems[i].LineAmount;
li.ItemCode = inv.LineItems[i].ItemCode;
li.Description = inv.LineItems[i].Description;
li.AccountCode = inv.LineItems[i].AccountCode;
li.UnitAmount = inv.LineItems[i].UnitAmount;
var categories = inv.Categories.Where(c => c.TicketChargeLineId == inv.LineItems[i].TicketChargeLineId);
foreach(var c in categories)
{
if(c.Value != "")
{
ItemTrackingCategory tc = new ItemTrackingCategory();
tc.Name = c.Name;
tc.Id = c.Id;
tc.Option = c.Value;
li.Tracking.Add(tc);
}
}
lineItems.Add(li);
It errors at li.Tracking.Add(tc)
. It gives the error "Object reference not set to an instance of an object.", however tc is not null. It does show an empty Guid for OptionId. Any assistance is greatly appreciated.