How to calculate the sum of successive specified inputs(only

Posted by Kanchana Gopalakrishnan on 28-Dec-2016 05:59

Here In my project, I need to add only the first two price of books of the library collection(for condition name="java") and return it in a decimal attribute(booksDecInfo)

If the iteration come across different name, the iteration must break.

Through this,

Though I have the same name, I must not add the 4th book's price to the returning value.

All Replies

Posted by mparish on 31-Dec-2016 21:06

Here’s one way to accomplish this.
I’ve simplified the vocab for this example
Remember that collections in Corticon are in an arbitrary order unless you explicitly sort them.
So the question is “what do you mean by the first two java books”
In this example I’ve sorted them by price and picked the first two.
But you could also sort by any other attribute in the data (eg a sequence number)
Notice also the use of the alias “javaBooks” along with the filter that defines what the alias actually means (type=’java’)
Notice also that the filter on books is also carried up to the Library.
Basically this says the rule sheet does not need to bother looking at libraries that have no java books at all.
Test Case
 
 
 
 

Posted by Kanchana Gopalakrishnan on 02-Jan-2017 01:40

Consider a collection in which we have name and price....

The Specified name(in condition) may be found in many instances or it may not be present in the collection....

If the first few attributes are with the specified name(in condition) and present subsequently, then I need the price values of those attributes to be added and displayed....

And if the specified name is not found subsequently, I don't want my price to be added.......

Here the important issue is >>>  For this process I don't want my collection to be sorted in any order.....

This thread is closed