on 2012 Oct 31 12:05 PM
Hi All,
We have implemented a project validation script that checks the length of a product category ID is 1 or gives the user an error. Our working script is:
ApplicationException ae = new ApplicationException(session);
catHome = IBeanHomeLocator.lookup(session, doc.getInternalCategory());
catBean = catHome.find(doc.getInternalCategory());
if (catBean.getCategoryId().length() != 1)
{
ae.chainAtEnd(doc.createApplicationException("INTERNAL_CAT", "CUSTOM", "prod_cat_1_error"));
}
if (ae.getChain() != null)
{
throw ae.getChain();
}
Due to a change in requirements it is now possible for the user to select no product category in the project. To make my script work I have been trying to use hasValue, however this keeps giving me the error: Attempt to resolve method: find() on undefined variable or class name: catHome
The change I made was:
ApplicationException ae = new ApplicationException(session);
if(hasValue(doc.getInternalCategory()))
{
catHome = IBeanHomeLocator.lookup(session, doc.getInternalCategory());
catBean = catHome.find(doc.getInternalCategory());
if (catBean.getCategoryId().length() != 1)
{
ae.chainAtEnd(doc.createApplicationException("INTERNAL_CAT", "CUSTOM", "prod_cat_1_error"));
}
}
if (ae.getChain() != null)
{
throw ae.getChain();
}
Is this incorrect use of hasValue ? What should I be using in this case?
Many Thanks
Dan
Request clarification before answering.
Hi Dan,
The usage of hasValue looks correct to me. Don’t see anything wrong. In fact, I copied your script and tried it and seems to be working ok. What version and SP are you on?
As a side note, instead of calling doc.getInternalCategory() multiple times, I’d store in a variable.
Something like…
intCat = doc.getInternalCategory();
if (hasValue(intCat)) {
catBean = IBeanHomeLocator.lookup(session, intCat).find(intCat);
}
Regards,
Vikram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vikram,
Thank you for your advice on storing variables.
I am using version 9.0.04.00
The code works fine when a product category with ID length one is chosen and gives the user an error message correctly if they choose a product category with ID length two, however if the product category field is left blank I am getting the Attempt to resolve method: find() on undefined variable or class name: catHome error message.
Thanks
Dan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.