Skip to Content
0
Former Member
Oct 31, 2012 at 12:05 PM

Correct use of hasValue in a script

47 Views

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