3 weeks ago
Hello Experts of CPI,
I have a requirement of mapping and below is the requirement which i am unable to get the output, please review and provide the best CPI UDF solution
I used create copies udf but it is not creating as shown in target value needed
1 source context values should repeat again and again by given count value
Source single context values context number of copies Target Value Needed
101.22 3 101.22
202.22 2 202.22
303.22 1 303.22
------------
101.22
202.22
------------
101.22
You have to convert the second parameter, so that it has the same number of context changes as the first one. Then the UDF will be called with both parameters as arrays. Each call will get matching contexts for each parameter one set at a time. Then you can loop on the second parameter and make copies of the first parameter. You won't get a cross product of the arguments.
You can change the second parameter to a list either by changing the context, by going one level up or using the function removeContext.
Here is for illustration a function that copies a value several times as specified by the second parameter. Your requirement is different.
def void copyManyTimes(String[] value, String[] count, Output output, MappingContext context) {
count.eachWithIndex { it,i ->
(it as Integer).times { output.addValue( value[i] ) }
output.addContextChange()
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dinu,
When i remove the second context change the values are not as expected
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dinu,
Thank you for the reply,
When i tested with your code I am getting a different result, please see the screen shot
First context should repeat it self based on second input count number
if count value in second context is 1 then repeat 1 time
if count value in second context is 5 then repeat 5 times
if count value in second context is 3 then repeat 3 times
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
9 | |
9 | |
7 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.