Need to split CDT elements

Certified Associate Developer

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{

amount,

date,

claimID,

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,

claimID:ri!cdt1.claimID,

claimType:ri!cdt1.claimType

)

)

),

 

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

Parents
  • Why are you trying to store the exact same amount value in two different CDTs? There definitely can be use cases for this type of deonormalization, but it seems to me that if two rows have the same value that this should be stored via a foreign key relationship instead of saving the data twice. This can lead to data corruption in your application if they ever fall out of sync. Once this issue pops up, it can be very painful to resolve.
Reply
  • Why are you trying to store the exact same amount value in two different CDTs? There definitely can be use cases for this type of deonormalization, but it seems to me that if two rows have the same value that this should be stored via a foreign key relationship instead of saving the data twice. This can lead to data corruption in your application if they ever fall out of sync. Once this issue pops up, it can be very painful to resolve.
Children
No Data