Hi,
i would like to make calculate from IG base on currency. at the header level, there are two currencies
at detail level of IG, there are many line items
i expect to make a calculation button to sum Net Amount base on currency then update into header level, so:
USD = 277.2
KHR = 28653.6
++++++
At the moment, i create DA for Calculation button with JS
var model = apex.region("IGITEMDATA").widget().interactiveGrid("getViews", "grid").model;
var n_amt, n_totamt = 0;
col_amt = model.getFieldKey("NETAMOUNT");
model.forEach(function(igrow) {
n_amt = parseFloat(igrow[col_amt], 10);
if (!isNaN(n_amt)) {
n_totamt += n_amt;
}
});
apex.item("P61_TOTALAMTPRCUR").setValue(n_totamt);
the result, i can pass total amount into header level with only one page item.
Thanks,
Ratana
Vinish Kapoor
Try this one:
ratana
thanks!
after testing, both page items show zero
i thought that cause of currency column, it is 'Select List' type
please help more.
Vinish Kapoor
There was a bug in the code above. I edited now, please try again.
ratana
i modified code:
var model = apex.region("IGITEMDATA").widget().interactiveGrid("getViews", "grid").model;
var n_amt_USD, n_totamt_USD = 0;
var n_amt_KHR, n_totamt_KHR = 0;
col_amt = model.getFieldKey("NETAMOUNT");
col_curr = model.getFieldKey("CURRENCY");
model.forEach(function(igrow) {
//loop USD currency
if (col_curr === 'USD')
{
n_amt_USD = parseFloat(igrow[col_amt], 10);
if (!isNaN(n_amt_USD))
{
n_totamt_USD += n_amt_USD;
}
} else
{
//loop KHR currency
n_amt_KHR = parseFloat(igrow[col_amt], 10);
if (!isNaN(n_amt_KHR))
{
n_totamt_KHR += n_amt_KHR;
}
}
});
apex.item("P61_TOTALAMTPRCUR").setValue(n_totamt_USD);
apex.item("P61_TOTALAMTSECUR").setValue(n_totamt_KHR);
Result: the amount goes to KHR page item only
it doesn't find USD currency.
thanks for your time.
Vinish Kapoor
Below is the modified code:
Now it should work. Please try and let me know.
ratana
the same result as previously. total amount sum into KHR page item.
Vinish Kapoor
It seems the value of igrow[col_curr] is not USD. You need to debug it using the consol.log() method. Put the below line after //loop USD currency comment:
Then inspect the browser element and click on the Console tab to view the value of this variable.
ratana
This is input data:
Add the code
console result:
please help me more.
Vinish Kapoor
Ok got it.
Now replace the USD to KHR in the if condition as follows:
And reverse the variable processing.
Also, Declare the variables on top:
That's it.
ratana
I modified the code:
var model = apex.region("IGITEMDATA").widget().interactiveGrid("getViews", "grid").model;
var n_amt_USD, n_totamt_USD = 0;
var n_amt_KHR, n_totamt_KHR = 0;
var col_amt;
var col_curr;
col_amt = model.getFieldKey("NETAMOUNT");
col_curr = model.getFieldKey("CURRENCY");
model.forEach(function(igrow) {
//loop USD currency
console.log(igrow[col_curr]);
if (igrow[col_curr] == 'USD')
{
n_amt_USD = parseFloat(igrow[col_amt], 10);
if (!isNaN(n_amt_USD))
{
n_amt_USD += n_amt_USD;
}
} else
{
//loop KHR currency
n_amt_KHR = parseFloat(igrow[col_amt], 10);
if (!isNaN(n_amt_KHR))
{
n_totamt_KHR += n_amt_KHR;
}
}
});
apex.item("P61_TOTALAMTPRCUR").setValue(n_totamt_USD);
apex.item("P61_TOTALAMTSECUR").setValue(n_totamt_KHR);
Two rows in IG:
Page Item returned value:
console result:
najeeb Alikhel
how to find total and net total automatically ?