I am trying to update existing datasource by comparing it with another datasource but getting an exception.
my code
private void loadPurchaseOrderDetails(){
// create a LoadContext
LoadContext<PurchaseOrderLine> loadContext = LoadContext.create(PurchaseOrderLine.class)
.setQuery(LoadContext.createQuery("select e from erp$PurchaseOrderLine e " +
"where e.purchaseOrder.id = :poid")
.setParameter("poid", materialReceiptVendorDs.getItem().getPurchaseOrder().getId()))
.setView("purchaseOrderLinePo-view"); //View.LOCAL or "purchaseRequisitionLinePR-view"
// load list using DataManager
List<PurchaseOrderLine> purchaseOrderLines = dataManager.loadList(loadContext);
BigDecimal receivedQty;
for (PurchaseOrderLine line : purchaseOrderLines) {
receivedQty = BigDecimal.ZERO;
if(PersistenceHelper.isNew(getItem())) {
MaterialReceiptVendorLine mr = metadata.create(MaterialReceiptVendorLine.class);
mr.setMaterial(line.getMaterial());
mr.setUnitOfMeasure(line.getUnitOfMeasure());
// mr.setQuantity(line.getQuantity().subtract(line.getReceivedQuantity()));
mr.setMaterialReceiptVendor(getItem());
mr.setPurchaseOrder(line.getPurchaseOrder());
mr.setPurchaseOrderLine(line);
if (line.getReceivedQuantity() != null) {
receivedQty = line.getReceivedQuantity();
} else {
receivedQty = line.getReceivedQuantity();
}
mr.setPoBalance(line.getQuantity().subtract(receivedQty));
materialReceiptVendorLineDs.addItem(mr);
}else{
for(MaterialReceiptVendorLine line1 : materialReceiptVendorLineDs.getItems()){
if(line.getId().equals(line1.getPurchaseOrderLine().getId())) {
if(line.getQuantity()==null){
materialReceiptVendorLineDs.getItem().setPoBalance(line.getQuantity().subtract(line.getReceivedQuantity()));
}else{
BigDecimal qty = new BigDecimal(100);
// materialReceiptVendorLineDs.getItem().setPoBalance(line.getQuantity().add(line1.getQuantity()).subtract(line.getReceivedQuantity()));
materialReceiptVendorLineDs.getItem().setPoBalance(line.getQuantity());
}
}
}
}
}
}
The exception is thrown from the following line of code above
materialReceiptVendorLineDs.getItem().setPoBalance(line.getQuantity());
exception:
java.lang.NullPointerException
at com.company.web.mm.materialreceiptvendor.MaterialReceiptVendorEdit.loadPurchaseOrderDetails(MaterialReceiptVendorEdit.java:233)
at com.company.erp.web.mm.materialreceiptvendor.MaterialReceiptVendorEdit.postInit(MaterialReceiptVendorEdit.java:125)
at com.haulmont.cuba.gui.components.AbstractEditor.setItem(AbstractEditor.java:70)
at com.haulmont.cuba.gui.WindowManager.openEditor(WindowManager.java:721)
at com.haulmont.cuba.web.WebWindowManager.openEditor(WebWindowManager.java:157)
at com.haulmont.cuba.gui.components.WindowDelegate.openEditor(WindowDelegate.java:250)
at com.haulmont.cuba.web.gui.WebWindow.openEditor(WebWindow.java:444)
at com.haulmont.cuba.gui.components.actions.EditAction.internalOpenEditor(EditAction.java:232)
at com.haulmont.cuba.gui.components.actions.EditAction.actionPerform(EditAction.java:225)
at com.haulmont.cuba.web.gui.components.WebButton.performAction(WebButton.java:44)