Hi All,
I need to retrieve supplier handler for contact when user logged in to Supplier Portal, there doc.getParentIBean() comes null so we cant directly fetch supplier from doc.getParentIBean() as in case when user logged in to buyer portal. In order to achieve my requirement, I am unnecessary fetching all vendors from database then fetching each contact comparing with logged in contact and then getting supplier external id. Though this piece of code is working fine but its crashing when we have lots and lots of vendors in DB hence hindering performance.
Is there any other way to retrieve supplier handler for contact(ContactIBeanIfc) when user logged in to Supplier Portal.
Thanks in Advance!!
I am using below piece of code:
if (doc.getParentIBean() == null) {
//get id of current logged in user
logIt("*** User logged in to Supplier Portal, checking the supplier id ***", 1);
userId = session.getAccount().getUserName();
logIt("*** Current logged in user has id " + userId + " ***", 1);
contactsList = contactHome.findWhere("NAME ='" + userId + "'");
if (contactsList.size() > 0 ) {
contact = (ContactIBeanIfc) contactsList.get(0);
contactDocUid = contact.getDocumentId();
vendorHome = (VendorIBeanHomeIfc)IBeanHomeLocator.lookup(session, VendorIBeanHomeIfc.sHOME_NAME);
vendorsList = vendorHome.findAll();
vsize = vendorsList.size();
for (int j = 0; j < vsize; j++) {
vendor = (VendorIBeanIfc) vendorsList.get(j);
conList = vendor.getCollnContact();
for (int k = 0; k < conList.size(); k++ ) {
childContact = (ContactIBeanIfc) conList.get(k);
if (contactDocUid.equals(childContact.getFieldMetadata("UNIQUE_DOC_NAME").get(childContact))) {
//Check if external supplier id is present
extSuppId = "";
businessSystems = vendor.getCollnLogicalSys();
if (hasValue(businessSystems)) {
if (businessSystems.size() > 0 ) {
bsys = (VendorLogSysIBeanIfc)businessSystems.get(0);
extSuppId = bsys.getExternalSupplierId();
}
}
if (hasValue(extSuppId)) {
supplierId = extSuppId;
logIt("*** External supplier id for this contact is " + supplierId + "***", 1);
isExternalSupplier = true;
} else {
supplierId = vendor.getExternalId();
logIt("*** Internal supplier id for this contact is " + supplierId + "***", 1);
isExternalSupplier = false;
}
break;
}
}
}
}
}