Unable to handle null condition in script callout

Help is preferred to those who publish their work as Open Source and not as private branches rejecting collaboration. Such projects are not maintainable and shall be deleted.
Forum rules
This forum is personally pruned to avoid redundant posts. Related topics are grouped together. IF YOU HAVE REGISTERED, you need to send email to red1(a)red1.org with your username in the subject title to get me to activate you.

Unable to handle null condition in script callout

Postby vivekjustthink » Wed Oct 24, 2012 2:13 pm

Hi,

For a long time, i am unable to handle null condition in script callout in adempiere. Just take a look at this beanshell script callout.

Script Name : beanshell:AlertProductMaximumLimitExcess

Code: Select all
maximumQty=DB.getSQLValueBD(null, "select level_max from m_replenish where m_product_id=?",mproductid);
if(maximumQty != null && maximumQty!=0 && maximumQty!=-1)
{        if(qty!= 0)       
         {       
               if(qty.compareTo(maximumqty)>0)
                       return Msg.getMsg("en_us",display);
         }
}


what ever the maximum qty is, the code get inside the if condition. i even specified it this way

Code: Select all
maximumQty = null;
if(maximumQty==null){
          return Msg.getMsg("en_us","maximum Qty is null");
}

Thanks for your help..

regards
vivek
vivekjustthink
 
Posts: 21
Joined: Thu Oct 04, 2012 5:32 pm

Re: Unable to handle null condition in script callout

Postby globalqss » Wed Oct 24, 2012 9:24 pm

Hi Vivek, can you paste the complete code of the callout? To check how are you initializing the mproductid and qty variables.

Also, if the maximumQty is BigDecimal - then comparing to integer doesn't sound right.

I think also that beanshell has some special management for nulls - AFAIR there is a NULL object - maybe like this:
http://www.beanshell.org/javadoc/bsh/Pr ... .html#NULL

Regards,

Carlos Ruiz
globalqss
Senior
 
Posts: 599
Joined: Thu Dec 29, 2005 4:15 am
Location: Bogotá, Colombia

Re: Unable to handle null condition in script callout

Postby vivekjustthink » Wed Oct 24, 2012 11:16 pm

Thank You so much carloz :lol: your hint was just enlightening.

Actually beanshell has the class Primitive as java has the class Object. 2 special fields are in class Primitive. They are NULL & VOID. Void means no data type, but a special type in beanshell and they say it for practical reasons.

In the following way we can handle null or void in beanshell.

Way 1
Code: Select all
qty=null;
if(qty==NULL){
A_Tab.setValue("Description","qty is null");
}else{
A_Tab.setValue("Description","qty is not null");
}


Way 2
Code: Select all
qty=null;
if(qty==VOID){
A_Tab.setValue("Description","qty is null");
}else{
A_Tab.setValue("Description","qty is not null");
}


Hope this is useful for others if they face the same problem. Once again a great thanks to Carlos... :D
vivekjustthink
 
Posts: 21
Joined: Thu Oct 04, 2012 5:32 pm

Re: Unable to handle null condition in script callout

Postby red1 » Sat Nov 03, 2012 9:45 am

Thank you Vivek for rephrasing the answer. This is also helpful to me to learn something i did not know before. :)
red1
Site Admin
 
Posts: 2759
Joined: Tue Jul 06, 2004 3:01 pm
Location: Kuala Lumpur, Malaysia

Re: Unable to handle null condition in script callout

Postby vivekjustthink » Sat Nov 03, 2012 12:45 pm

:D
vivekjustthink
 
Posts: 21
Joined: Thu Oct 04, 2012 5:32 pm


Return to HELP ME!!!

Who is online

Users browsing this forum: No registered users and 1 guest

cron