Hello Friends,
I have created following java function with delegator. ---------------------------------------------------------------------------- public static String getOrderSubTotal(GenericDelegator delegator, String OTCMOrderNo) { List subTotalObject = null; try { List fieldsToSelect = UtilMisc.toList("OTCMOrderSubTotal"); EntityConditionList whereConditions = new EntityConditionList(UtilMisc.toList( new EntityExpr("OTCMOrderNo", EntityOperator.EQUALS, OTCMOrderNo), new EntityExpr("OTCMAdjustmentAmountType", EntityOperator.EQUALS, "SHIPPING_CHARGES"), new EntityExpr("OTCMContactType", EntityOperator.EQUALS, "SHIPPING_LOCATION") ), EntityOperator.AND); subTotalObject = delegator.findByCondition("OrderAndTaxByCounty", whereConditions, null, fieldsToSelect, null, null); } catch (GenericEntityException e) { Debug.logError(e, "Error finding OrderAndTaxByCounty in getPartyName", module); } String subTotal = String.valueOf(subTotalObject); return subTotal; } ------------------------------------------------------------------------------------- I am trying to call this java function in Form widget with <display description="${bsh:com.opensourcestrategies.financials.reports.ReportHelper.getOrderSubTotal(delegator, OTCMOrderNo)}"/> The "return Subtotal" in my java class prints ------------------------------------------------------------------------------------- [[GenericEntity:OrderAndTaxByCounty][OTCMOrderSubTotal,104.85(java.lang.Double)]] ------------------------------------------------------------------------------------- I need to just print 104.85. Is there anyway to just get that part ? As you can see it is printing lot of extra stuff. |
This line will return a GenericEntity, not the single selected field:
subTotalObject = delegator.findByCondition Change the bottom of your method to something like... String subTotal = String.valueOf(subTotalObject.get ("OTCMOrderSubTotal")); Bob On 2009-09-29, at 11:03 PM, su2 <[hidden email]> wrote: > > Hello Friends, > > I have created following java function with delegator. > > --- > --- > ---------------------------------------------------------------------- > public static String getOrderSubTotal(GenericDelegator delegator, > String > OTCMOrderNo) { > List subTotalObject = null; > > > try { > > List fieldsToSelect = UtilMisc.toList > ("OTCMOrderSubTotal"); > > EntityConditionList whereConditions = new > EntityConditionList(UtilMisc.toList( > new EntityExpr("OTCMOrderNo", > EntityOperator.EQUALS, > OTCMOrderNo), > new EntityExpr("OTCMAdjustmentAmountType", > EntityOperator.EQUALS, "SHIPPING_CHARGES"), > new EntityExpr("OTCMContactType", > EntityOperator.EQUALS, > "SHIPPING_LOCATION") > ), EntityOperator.AND); > > subTotalObject = delegator.findByCondition > ("OrderAndTaxByCounty", > whereConditions, null, fieldsToSelect, null, null); > > > } catch (GenericEntityException e) { > Debug.logError(e, "Error finding OrderAndTaxByCounty in > getPartyName", module); > } > > String subTotal = String.valueOf(subTotalObject); > > return subTotal; > > } > --- > --- > --- > --- > --- > ---------------------------------------------------------------------- > > I am trying to call this java function in Form widget with > > <display > description="$ > {bsh:com.opensourcestrategies.financials.reports.ReportHelper.getOrderSubTotal( > delegator, > OTCMOrderNo)}"/> > > The "return Subtotal" in my java class prints > > --- > --- > --- > --- > --- > ---------------------------------------------------------------------- > [[GenericEntity:OrderAndTaxByCounty][OTCMOrderSubTotal,104.85 > (java.lang.Double)]] > --- > --- > --- > --- > --- > ---------------------------------------------------------------------- > I need to just print 104.85. Is there anyway to just get that part ? > As you > can see it is printing lot of extra stuff. > -- > View this message in context: http://www.nabble.com/How-to-get-value-from-the-delegator-object-declared-as-list-which-has-only-one-value--tp25674270p25674270.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > |
Another side note, it would be better to have your method return the
double. The bsh from your screen will handle the conversion. Moreover, I believe that you can indicate that your display element represents a currency and get proper localized formatting. Bob On 2009-09-30, at 12:43 AM, [hidden email] wrote: > This line will return a GenericEntity, not the single selected field: > subTotalObject = delegator.findByCondition > > Change the bottom of your method to something like... > > String subTotal = String.valueOf(subTotalObject.get > ("OTCMOrderSubTotal")); > > Bob > > On 2009-09-29, at 11:03 PM, su2 <[hidden email]> wrote: > >> >> Hello Friends, >> >> I have created following java function with delegator. >> >> --- >> --- >> --- >> ------------------------------------------------------------------- >> public static String getOrderSubTotal(GenericDelegator delegator, >> String >> OTCMOrderNo) { >> List subTotalObject = null; >> >> >> try { >> >> List fieldsToSelect = UtilMisc.toList >> ("OTCMOrderSubTotal"); >> >> EntityConditionList whereConditions = new >> EntityConditionList(UtilMisc.toList( >> new EntityExpr("OTCMOrderNo", >> EntityOperator.EQUALS, >> OTCMOrderNo), >> new EntityExpr("OTCMAdjustmentAmountType", >> EntityOperator.EQUALS, "SHIPPING_CHARGES"), >> new EntityExpr("OTCMContactType", >> EntityOperator.EQUALS, >> "SHIPPING_LOCATION") >> ), EntityOperator.AND); >> >> subTotalObject = delegator.findByCondition >> ("OrderAndTaxByCounty", >> whereConditions, null, fieldsToSelect, null, null); >> >> >> } catch (GenericEntityException e) { >> Debug.logError(e, "Error finding OrderAndTaxByCounty in >> getPartyName", module); >> } >> >> String subTotal = String.valueOf(subTotalObject); >> >> return subTotal; >> >> } >> --- >> --- >> --- >> --- >> --- >> --- >> ------------------------------------------------------------------- >> >> I am trying to call this java function in Form widget with >> >> <display >> description="$ >> {bsh:com.opensourcestrategies.financials.reports.ReportHelper.getOrderSubTotal( >> delegator, >> OTCMOrderNo)}"/> >> >> The "return Subtotal" in my java class prints >> >> --- >> --- >> --- >> --- >> --- >> --- >> ------------------------------------------------------------------- >> [[GenericEntity:OrderAndTaxByCounty][OTCMOrderSubTotal,104.85 >> (java.lang.Double)]] >> --- >> --- >> --- >> --- >> --- >> --- >> ------------------------------------------------------------------- >> I need to just print 104.85. Is there anyway to just get that >> part ? As you >> can see it is printing lot of extra stuff. >> -- >> View this message in context: http://www.nabble.com/How-to-get-value-from-the-delegator-object-declared-as-list-which-has-only-one-value--tp25674270p25674270.html >> Sent from the OFBiz - User mailing list archive at Nabble.com. >> |
In reply to this post by su2
Hi Su,
Look at the "findByCondition" method, it returns a list, if you are sure that this list contains only one item then you can get it from orderAndTaxByCounty = subTotalObject.get(0) and then return( orderAndTaxByCounty.get("OTCMOrderSubTotal")) would work for you. -- Regards Sumit Pandit On 30-Sep-09, at 8:33 AM, su2 wrote: > > Hello Friends, > > I have created following java function with delegator. > > ---------------------------------------------------------------------------- > public static String getOrderSubTotal(GenericDelegator delegator, > String > OTCMOrderNo) { > List subTotalObject = null; > > > try { > > List fieldsToSelect = > UtilMisc.toList("OTCMOrderSubTotal"); > > EntityConditionList whereConditions = new > EntityConditionList(UtilMisc.toList( > new EntityExpr("OTCMOrderNo", > EntityOperator.EQUALS, > OTCMOrderNo), > new EntityExpr("OTCMAdjustmentAmountType", > EntityOperator.EQUALS, "SHIPPING_CHARGES"), > new EntityExpr("OTCMContactType", > EntityOperator.EQUALS, > "SHIPPING_LOCATION") > ), EntityOperator.AND); > > subTotalObject = > delegator.findByCondition("OrderAndTaxByCounty", > whereConditions, null, fieldsToSelect, null, null); > > > } catch (GenericEntityException e) { > Debug.logError(e, "Error finding OrderAndTaxByCounty in > getPartyName", module); > } > > String subTotal = String.valueOf(subTotalObject); > > return subTotal; > > } > ------------------------------------------------------------------------------------- > > I am trying to call this java function in Form widget with > > <display > description="$ > {bsh:com > .opensourcestrategies > .financials.reports.ReportHelper.getOrderSubTotal(delegator, > OTCMOrderNo)}"/> > > The "return Subtotal" in my java class prints > > ------------------------------------------------------------------------------------- > [[GenericEntity:OrderAndTaxByCounty][OTCMOrderSubTotal, > 104.85(java.lang.Double)]] > ------------------------------------------------------------------------------------- > I need to just print 104.85. Is there anyway to just get that part ? > As you > can see it is printing lot of extra stuff. > -- > View this message in context: http://www.nabble.com/How-to-get-value-from-the-delegator-object-declared-as-list-which-has-only-one-value--tp25674270p25674270.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > |
In reply to this post by Bob Morley
Thanks Bob for the response.
Yes, You are correct, the "delegator.findByCondition" returns a GenericEntity. I think subTotalObject.get("OTCMOrderSubTotal") will not help me as .get(int index) - it takes only int index. That is where I am stuck, as I am not sure how can I directly reference my desired value. It would be helpful if you can share the idea. Thank you. Su-
|
In reply to this post by Sumit Pandit-3
Hi Sumit,
Yes it returns 1 item but its in GenericEntity ([[GenericEntity:OrderAndTaxByCounty][OTCMOrderSubTotal, 104.85(java.lang.Double)]]) format. I am not sure how to directly refer/get my desired value. Let me know if you have any idea. Thank you. Su-
|
Su,
It is very simple - it is to fetch the field from the map which is in a list. I already wrote the code in previous mail. Follow that code and get the data. Regards Sumit Pandit On 30-Sep-09, at 6:19 PM, su2 wrote: > > Hi Sumit, > > Yes it returns 1 item but its in GenericEntity > ([[GenericEntity:OrderAndTaxByCounty][OTCMOrderSubTotal, > 104.85(java.lang.Double)]]) format. I am not sure how to directly > refer/get > my desired value. > > Let me know if you have any idea. > > Thank you. > Su- > > Sumit Pandit-3 wrote: >> >> Hi Su, >> >> Look at the "findByCondition" method, it returns a list, if you are >> sure that this list contains only one item then you can get it from >> orderAndTaxByCounty = subTotalObject.get(0) and then >> return( orderAndTaxByCounty.get("OTCMOrderSubTotal")) would work for >> you. >> >> -- >> Regards >> Sumit Pandit >> >> On 30-Sep-09, at 8:33 AM, su2 wrote: >> >>> >>> Hello Friends, >>> >>> I have created following java function with delegator. >>> >>> ---------------------------------------------------------------------------- >>> public static String getOrderSubTotal(GenericDelegator delegator, >>> String >>> OTCMOrderNo) { >>> List subTotalObject = null; >>> >>> >>> try { >>> >>> List fieldsToSelect = >>> UtilMisc.toList("OTCMOrderSubTotal"); >>> >>> EntityConditionList whereConditions = new >>> EntityConditionList(UtilMisc.toList( >>> new EntityExpr("OTCMOrderNo", >>> EntityOperator.EQUALS, >>> OTCMOrderNo), >>> new EntityExpr("OTCMAdjustmentAmountType", >>> EntityOperator.EQUALS, "SHIPPING_CHARGES"), >>> new EntityExpr("OTCMContactType", >>> EntityOperator.EQUALS, >>> "SHIPPING_LOCATION") >>> ), EntityOperator.AND); >>> >>> subTotalObject = >>> delegator.findByCondition("OrderAndTaxByCounty", >>> whereConditions, null, fieldsToSelect, null, null); >>> >>> >>> } catch (GenericEntityException e) { >>> Debug.logError(e, "Error finding OrderAndTaxByCounty in >>> getPartyName", module); >>> } >>> >>> String subTotal = String.valueOf(subTotalObject); >>> >>> return subTotal; >>> >>> } >>> ------------------------------------------------------------------------------------- >>> >>> I am trying to call this java function in Form widget with >>> >>> <display >>> description="$ >>> {bsh:com >>> .opensourcestrategies >>> .financials.reports.ReportHelper.getOrderSubTotal(delegator, >>> OTCMOrderNo)}"/> >>> >>> The "return Subtotal" in my java class prints >>> >>> ------------------------------------------------------------------------------------- >>> [[GenericEntity:OrderAndTaxByCounty][OTCMOrderSubTotal, >>> 104.85(java.lang.Double)]] >>> ------------------------------------------------------------------------------------- >>> I need to just print 104.85. Is there anyway to just get that part ? >>> As you >>> can see it is printing lot of extra stuff. >>> -- >>> View this message in context: >>> http://www.nabble.com/How-to-get-value-from-the-delegator-object-declared-as-list-which-has-only-one-value--tp25674270p25674270.html >>> Sent from the OFBiz - User mailing list archive at Nabble.com. >>> >> >> >> > > -- > View this message in context: http://www.nabble.com/How-to-get-value-from-the-delegator-object-declared-as-list-which-has-only-one-value--tp25674270p25680369.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > |
Hi Sumit,
I tried the code. But I am getting error. Error says that to use "orderAndTaxByCounty = subTotalObject.get(0)", orderAndTaxByCounty should be defined as object and orderAndTaxByCounty.get("OTCMOrderSubTotal") is not allowed with the object. Sorry, If I am misunderstanding the code. Thank you. Su-
|
In reply to this post by su2
Hey Su,
Here is how I would code the method: public static BigDecimal getOrderSubTotal(GenericDelegator delegator, String OTCMOrderNo) { BigDecimal subTotal = BigDecimal.ZERO; try { EntityCondition condition = EntityCondition.makeCondition( UtilMisc.toMap("OTCMOrderNo", OTCMOrderNo, "OTCMAdjustmentAmountType", "SHIPPING_CHARGES", "OTCMContactType", "SHIPPING_LOCATION")); List<GenericValue> subTotals = delegator.findList("OrderAndTaxByCounty", condition, null, null, null, false); if (subTotals.size() > 0) { GenericValue subTotalEntity = subTotals.get(0); subTotal = subTotalEntity.getBigDecimal("OTCMOrderSubTotal"); } } catch (GenericEntityException e) { Debug.logError(e, "Error finding OrderAndTaxByCounty in getPartyName", module); } return subTotal; } I did not test this, but the key point is that the findList is used (instead of findCondition which is depreciated). It returns a list (as someone else had pointed out) so we check the size to ensure we have at least one result, and then get the first GenericEntity and form it get your field (OTCMOrderSubTotal). Usually numbers in the system are BigDecimal so I found it interesting that in your view- entity you have it come up as a double. You could certainly change this code to use the double; but I would look at possibly changing to a BigDecimal because I am guessing that the underlying entities that your v-e is based on use that data type. On Sep 30, 2009, at 8:47 AM, su2 wrote: > > Thanks Bob for the response. > > Yes, You are correct, the "delegator.findByCondition" returns a > GenericEntity. > > I think subTotalObject.get("OTCMOrderSubTotal") will not help me > as .get(int > index) - it takes only int index. That is where I am stuck, as I am > not sure > how can I directly reference my desired value. > > It would be helpful if you can share the idea. > > Thank you. > Su- > > > Bob Morley wrote: >> >> This line will return a GenericEntity, not the single selected field: >> subTotalObject = delegator.findByCondition >> >> Change the bottom of your method to something like... >> >> String subTotal = String.valueOf(subTotalObject.get >> ("OTCMOrderSubTotal")); >> >> Bob >> >> On 2009-09-29, at 11:03 PM, su2 <[hidden email]> wrote: >> >>> >>> Hello Friends, >>> >>> I have created following java function with delegator. >>> >>> --- >>> --- >>> ---------------------------------------------------------------------- >>> public static String getOrderSubTotal(GenericDelegator delegator, >>> String >>> OTCMOrderNo) { >>> List subTotalObject = null; >>> >>> >>> try { >>> >>> List fieldsToSelect = UtilMisc.toList >>> ("OTCMOrderSubTotal"); >>> >>> EntityConditionList whereConditions = new >>> EntityConditionList(UtilMisc.toList( >>> new EntityExpr("OTCMOrderNo", >>> EntityOperator.EQUALS, >>> OTCMOrderNo), >>> new EntityExpr("OTCMAdjustmentAmountType", >>> EntityOperator.EQUALS, "SHIPPING_CHARGES"), >>> new EntityExpr("OTCMContactType", >>> EntityOperator.EQUALS, >>> "SHIPPING_LOCATION") >>> ), EntityOperator.AND); >>> >>> subTotalObject = delegator.findByCondition >>> ("OrderAndTaxByCounty", >>> whereConditions, null, fieldsToSelect, null, null); >>> >>> >>> } catch (GenericEntityException e) { >>> Debug.logError(e, "Error finding OrderAndTaxByCounty in >>> getPartyName", module); >>> } >>> >>> String subTotal = String.valueOf(subTotalObject); >>> >>> return subTotal; >>> >>> } >>> --- >>> --- >>> --- >>> --- >>> --- >>> ---------------------------------------------------------------------- >>> >>> I am trying to call this java function in Form widget with >>> >>> <display >>> description="$ >>> {bsh:com >>> .opensourcestrategies >>> .financials.reports.ReportHelper.getOrderSubTotal( >>> delegator, >>> OTCMOrderNo)}"/> >>> >>> The "return Subtotal" in my java class prints >>> >>> --- >>> --- >>> --- >>> --- >>> --- >>> ---------------------------------------------------------------------- >>> [[GenericEntity:OrderAndTaxByCounty][OTCMOrderSubTotal,104.85 >>> (java.lang.Double)]] >>> --- >>> --- >>> --- >>> --- >>> --- >>> ---------------------------------------------------------------------- >>> I need to just print 104.85. Is there anyway to just get that part ? >>> As you >>> can see it is printing lot of extra stuff. >>> -- >>> View this message in context: >>> http://www.nabble.com/How-to-get-value-from-the-delegator-object-declared-as-list-which-has-only-one-value--tp25674270p25674270.html >>> Sent from the OFBiz - User mailing list archive at Nabble.com. >>> >> >> > > -- > View this message in context: http://www.nabble.com/How-to-get-value-from-the-delegator-object-declared-as-list-which-has-only-one-value--tp25674270p25680328.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > Robert Morley Software Developer Emforium Group Inc. ALL-IN Software™ 519-772-6824 ext 220 [hidden email] |
Hi Bob,
I was trying to follow your suggestion (my function name is getOrderSubTotal1) and I am getting some errors. 1) The method makeCondition(Map) is undefined for the type EntityCondition I added following method in GenericDelegater.java to resolve the error. public List<GenericValue> findList(String string, EntityCondition condition, Object object, Object object2, Object object3, boolean b) { // TODO Auto-generated method stub return null; } 2) The method findList(String, EntityCondition, null, null, null, boolean) is undefined for the type GenericDelegator I added following method to EntityCondition.java to resolve the error. public static EntityCondition makeCondition(Map map) { // TODO Auto-generated method stub return null; } 3) After resolving above errors. After compiling and restarting the system, in Log file I get following error. ---------------------------------------------------------------- Error evaluating BSH scriplet [com.opensourcestrategies.financials.reports.ReportHelper.getOrderSubTotal1(delegator, OTCMOrderNo)], inserting nothing; error was: Sourced file: inline evaluation of: ``com.opensourcestrategies.financials.reports.ReportHelper.getOrderSubTotal1(deleg . . . '' : Method Invocation com.opensourcestrategies.financials.reports.ReportHelper.getOrderSubTotal1 : at Line: 1 : in file: inline evaluation of: ``com.opensourcestrategies.financials.reports.ReportHelper.getOrderSubTotal1(deleg . . . '' : com .opensourcestrategies .financials .reports .ReportHelper .getOrderSubTotal1 ( delegator , OTCMOrderNo ) Target exception: java.lang.NullPointerException Exception: bsh.TargetError Message: Sourced file: inline evaluation of: ``com.opensourcestrategies.financials.reports.ReportHelper.getOrderSubTotal1(deleg . . . '' : Method Invocation com.opensourcestrategies.financials.reports.ReportHelper.getOrderSubTotal1 ---------------------------------------------------------------- Do you know, what wrong is in my code? Thank you for the help. Su-
|
Free forum by Nabble | Edit this page |