Access Line item data in Invoices

Hi All,

I am having trouble with accessing data from the line items in a logic hook, the code I am using is below, when I call get_linked_beans I am being returned an empty Array even when modifying an already saved invoice. If anyone could give some insight into what might be going wrong that would be great.



function allocateTrees($bean, $event, $arguments) 
                if($bean->status == "Paid" && $bean->allocated_c != 1){
				$line_items = $bean->get_linked_beans('aos_invoices_aos_product_quotes','AOS_Products_Quotes');

				//load all line items relationships
				foreach($line_items as $line_item) 
					$bean->free_text_c = $bean->free_text_c.$line_item;

					$product = $line_item->get_linked_beans('aos_product_quotes_aos_products','AOS_Products');
					if ($product->name == "Trees"){
						//if the line item is a tree planting than we update the cumulative trees field.
						$bean->cumulative_trees_c += $line_item->product_qty;
						$bean->free_text_c = "Trees";
						$product->current_count_c += $line_item->product_qty;
					} else {
						//if it isn't a tree assume 1 to 1 for tonnage
					 	$bean->free_text_c = "Tonnage";
					 	$product->current_count_c += $line_item->product_qty;
				//set that the invoice has completed allocations.
				$bean->description = $line_items[1]->id;
				$bean->allocated_c = 1;
			} elseif ($bean->allocated_c != 2) {
				//invoice unpaid or already allocated - some other logic will be added here later.
                                $bean->allocated_c = 2;

I am assuming you are using invoices, and looking at invoices there is no field def for ‘aos_invoices_aos_product_quotes’, I assume you want to use ‘aos_products_quotes’