Show/Hide Toolbars

When searching for or filtering line items that are associated with an invoice, use the Invoice Repository's readInvoicesByCriteria method. In the definition of the fieldPathExpression.setSearchKeyPath, use the properties defined in the type class, LineItem, to identify which line item fields to use as search criteria.

The following example filters an invoice's line items based on associated project, fee line items, and a given timekeeper.

Code Snippet

//for this example, it is assumed that at least one invoice line item record that meets the search criterion already exists

protected InvoiceRepository invoiceRepository;

public void searchInvoices() throws Exception {

ObjectFieldCriterion fieldCriterion1 = new ObjectFieldCriterion();

fieldCriterion.setComparator(ObjectComparator.EQUALS);

LegacySearchFieldPathExpression fieldPathExpression1 = new LegacySearchFieldPathExpression();

fieldPathExpression1.setSearchKeyPath("lineItemList.project.primaryKey");

fieldCriterion1.setFieldPath(fieldPathExpression1);

fieldCriterion.setValue("DISP_1007");

FieldSearchClause searchCriteria = new FieldSearchClause();

searchCriteria.setOperator(LogicOperator.AND);

searchCriteria.getCriteria().add(fieldCriterion1);

//the following section defines a second fieldCriterion item for filtering fee line items

StringFieldCriterion fieldCriterion2 = new StringFieldCriterion();

fieldCriterion.setComparator(StringComparator.EQUALS_ENFORCE_CASE);

LegacySearchFieldPathExpression fieldPathExpression2 = new LegacySearchFieldPathExpression();

fieldPathExpression2.setSearchKeyPath("lineItem.type");

fieldCriterion2.setFieldPath(fieldPathExpression2);

fieldCriterion.setValue("FEE");

searchCriteria.getCriteria().add(fieldCriterion2);

//the following section defines a third fieldCriterion item for filtering line items associated with a given timekeeper

StringFieldCriterion fieldCriterion3 = new StringFieldCriterion();

fieldCriterion.setComparator(StringComparator.EQUALS_ENFORCE_CASE);

LegacySearchFieldPathExpression fieldPathExpression3 = new LegacySearchFieldPathExpression();

fieldPathExpression3.setSearchKeyPath("lineItem.timekeeper.uniqueKey");

fieldCriterion3.setFieldPath(fieldPathExpression3);

fieldCriterion.setValue("CONT_1010");

searchCriteria.getCriteria().add(fieldCriterion3);

List<Invoice> invoices = invoiceRepository.readInvoicesByCriteria(searchCriteria, 100, getPropertiesToRead());

}

private List<String> getPropertiesToRead() {

List<String> properties = new List<String>();

properties.add("numberString");

properties.add("invoiceDate");

properties.add("vendor");

properties.add("lineItems.version");

properties.add("lineItems.itemNumber");

properties.add("lineItems.serviceDate");

properties.add("lineItems.version");

properties.add("lineItems.originalRate");

properties.add("lineItems.originalQuantity");

properties.add("lineItems.originalDiscount");

properties.add("lineItems.originalTotal");

properties.add("lineItems.adjustedTotal");

return properties;

}