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 <[email protected]> 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
[email protected]