Hello All,
I'm creating an application where there is a requirement to update one of the field of a cdt with the same field of another cdt and store the output into third variable. My scenario for the said work is as below
Suppose my two cdt's are as below
cdt1{
amount,
claimID,
claimType
},
cdt2{
date,
claimType,
owner
}
Now all i need is to search both the cdt on the basis of claimID and claimType and if any both the matching values found then replace the amount of cdt1 with the amount in cdt2 or else keep it as it is. To accomplish this function I wrote the below logic
in Parent Interface
local!var1:a!foreach(
items:local!cdt1,
expression:rule!secondrule(
cdt1:local!cdt1[fv!index],
cdt2:local!cdt2
)
and in the secondrule file, I wrote the below logic
a!foreach(
items:local!cdt2,
expression{
if(
and(
ri!cdt2[fv!index].claimType=ri!cdt1.claimType,
ri!cdt2[fv!index].claimID=ri!cdt1.claimID
),
type!cdt1(
amount:ri!cdt2[fv!index].amount,
claimID:ri!cdt1.claimID,
claimType:ri!cdt1.claimType
type!cdt2(
amount:ri!cdt1.amount,
Now the problem that is happening here is related to the final cdt i'm getting. Suppose both cdt have 2 records. Out of which cdt1 has both the records different i.e combination of claimID and claimType is different but in cdt2 both the records are similar i.e claimID and claimType combination is same in both the records. do due to that i'm unfortunately getting the final cdt which has data like
[amount:500,claimID:10,ClaimType:2],[amount:600,claimID:20,ClaimType:3],
[amount:500,claimID:10,ClaimType:2]
Here the first two element is considered as a single item which is not acceptable. So is there a way where I can convert this elements into different array item and my totalcount would be 3 instead of 2? By that I can use union clause to remove the duplicate item. I hope my requirement is clear. Any suggestion here would be appreciated
Discussion posts and replies are publicly visible
Hopefully this is what you want, or at least will help get you to where you need to be. Note that the extra index(..., 1...) for local!matchesOnClaimIdAndClaimType isn't required if you have an "is null or empty" rule available to use in the if() towards the end of the rule.
load( local!arrayOfCdt1: { {amount:100, claimId: 10, claimType: 1}, {amount:100, claimId: 10, claimType: 1}, {amount:200, claimId: 20, claimType: 2}, {amount:700, claimId: 10, claimType: 2}, }, local!arrayOfCdt2: { {amount:110, claimId: 11, claimType: 1}, {amount:110, claimId: 11, claimType: 1}, {amount:210, claimId: 20, claimType: 1}, {amount:710, claimId: 20, claimType: 2}, }, a!forEach( items: local!arrayOfCdt1, expression: with( local!matchesOnClaimId: index( local!arrayOfCdt2, wherecontains( fv!item.claimId, local!arrayOfCdt2.claimId ), {} ), local!matchesOnClaimIdAndClaimType: index( index( local!matchesOnClaimId, wherecontains( fv!item.claimType, local!matchesOnClaimId.claimType ), null ), 1, null ), if( isnull( local!matchesOnClaimIdAndClaimType ), fv!item, local!matchesOnClaimIdAndClaimType ) ) ) )
Hi as per your explanation, what I understood is, finally you are getting an array as the response which has 3 items in it where one of the item is duplicate. Which can be resolved by union() as you already have mention,
But still I don't understand the meaning of "first two element is considered as a single item" why first 2 items will be considered as single item?
Also as I can see, you have a duplicate item so why are you considering this duplicate item? I believe the totalCount should be 2 instead of 3 unless you want to retain the duplicate values as well.