Get most recent entry from referenced app in calculation field
Hello,
I have a master app when i have product details and an other app where i store history of orders related to each product.
Using the calculation field in the master app you can easily show the sum, avg, or max values from the orders app but i want to show the quantity from the most recent order
the problem is when you reference an other app in the calculation field you get an array "@All of Quantity" ,where quantity is field in the orders app,this array contains integer values. if i can get an array of objects then i can probably use javascript to sort those objects based on date field and get the first element
Can anyone think of a way to do that ?
-
Hi Omar,
the latest related Order (= last element in the array) you get with:
@all of Quantity[@all of Quantity.length-1]
The oldest you get with:
@all of Quantity[0]
Rainer
rg@delos-consulting.com -
That doesn't really work because the order in the array is based on the order you added the item in
so if you add item 1 then 2 then then @all of Quantity[@all of Quantity.length-1] = 2
but if you add 2 then 1 then @all of Quantity[@all of Quantity.length-1]=1
what i'm looking for is that in the order history i have date field and i want to return the most recent order regardless what was the order they were added in -
This should work:
var allDate = @all of datefield; var maxDate = moment(@max of date).format("YYYYMMDDhhmm"); var quant = @all of quantity; result = 0; for(var i = 0; i < allDate.length; i++){ if(moment(allDate[i].format("YYYYMMDDhhmm") == maxDate){ result +=quant[i] } };
Rainer
rg@delos-consulting.com
Please sign in to leave a comment.
Comments
10 comments