How to retrieve more than one record using collections?

Posted by Kanchana Gopalakrishnan on 30-Dec-2016 01:53

I receiving the same first record twice....

What I must do to resolve by getting two records...?

Posted by mparish on 30-Dec-2016 04:14

In your test data you start with two (empty) result objects:
The rules as written are asking for EVERY instance of result to be set EVERY time rule 1 fires (which is twice – once for 001 and once for 002)
 
It does this each time the rule fires.
So it will first set both results based on the match with inc_id = 001
Then it will set both result based on the match with inc_id= 002
The net effect is that you end up with both result objects set to the last values processed.
 
If you want one of the results to be set for 001 and the other set for 002 then you need some way to distinguish the two result instances.
One way is to put the different  inc_ids in the two result objects and then add a filter like this
result.inc_id = indv_inc.inc_id
But how do you know there will only be two of them? It seems quite likely that the number is arbitrary.
 
An alternative is not to supply the empty result objects in the input at all.
but rather use this syntax in the action:
result.newUnique[inc=indv_inc_rev.inc, indv_id=indv_inc.inc_id,inc_type=indv_inc.inc_type,idv_id=indv_inc.indv_id]
Then each time rule 1 finds a match a new instance of result will be created
 
Also why do you have the Result objects unconnected to the case? I see in your scope you do show results associated with a case but you are not updating those.
If you want your results to be stored there then you would use this syntax by referring to the alias res:
res+= result.newUnique[inc=indv_inc_rev.inc, indv_id=indv_inc.inc_id,inc_type=indv_inc.inc_type,idv_id=indv_inc.indv_id]
 
Also as a preferred best practice I would suggest starting your entity names with an uppercase letter (eg Result)
And then use lowercase letters at the start of any association role names and at the start of any attribute names
 

All Replies

Posted by mparish on 30-Dec-2016 04:14

In your test data you start with two (empty) result objects:
The rules as written are asking for EVERY instance of result to be set EVERY time rule 1 fires (which is twice – once for 001 and once for 002)
 
It does this each time the rule fires.
So it will first set both results based on the match with inc_id = 001
Then it will set both result based on the match with inc_id= 002
The net effect is that you end up with both result objects set to the last values processed.
 
If you want one of the results to be set for 001 and the other set for 002 then you need some way to distinguish the two result instances.
One way is to put the different  inc_ids in the two result objects and then add a filter like this
result.inc_id = indv_inc.inc_id
But how do you know there will only be two of them? It seems quite likely that the number is arbitrary.
 
An alternative is not to supply the empty result objects in the input at all.
but rather use this syntax in the action:
result.newUnique[inc=indv_inc_rev.inc, indv_id=indv_inc.inc_id,inc_type=indv_inc.inc_type,idv_id=indv_inc.indv_id]
Then each time rule 1 finds a match a new instance of result will be created
 
Also why do you have the Result objects unconnected to the case? I see in your scope you do show results associated with a case but you are not updating those.
If you want your results to be stored there then you would use this syntax by referring to the alias res:
res+= result.newUnique[inc=indv_inc_rev.inc, indv_id=indv_inc.inc_id,inc_type=indv_inc.inc_type,idv_id=indv_inc.indv_id]
 
Also as a preferred best practice I would suggest starting your entity names with an uppercase letter (eg Result)
And then use lowercase letters at the start of any association role names and at the start of any attribute names
 

This thread is closed