Hi,
I am trying to find out an error regarding some logic in my map. Please find below next source and target structures:

The logic required is next one: each field is a map to map, excepts on the ones named "field".
Segment is 0..1 so it is possible that no fields should come here, and if exists then the segment1 may come 1 or more times. If there are segments (at least 1 to unbounded) then I need to search for value "AA" in field2 (on the source request). If the value exists then I need to send all those context values to the target (field1 to field1, field2 to field2, etc). If the value "AA" doesn't exist in field2 or if there is no segment then I need to send a 0 to all field target.
I am able to search for the AA value in field2 using an UDF:


field1 & field2 are the input parameters to the searchAA UDF and their context are at row level.
This is working for any test cases I've done:




But this is not working as expected when more than 1 row exist:

I might be missing something, or probable I need to avoid UDF and use only standard node functions but I can't understand the queue context error.
Is anyone able to let me know must I do this mapping logic so all test cases are good?
Thanks!!!!!!
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Evgeniy,
Thank you!!!!! I was missing the map with default at the end of the if sentence.
This solved my issue!
Happy to be of some help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This because of context handling.
1. Map source row to target row one to one
2. Map rowfield1,2,3 to Target rowfield1,2,3 one to one
3. Now apply the field1 logic as per my previous answer but always right click on field1 and go to context and select context from segment 1 to row.
You need to do.this context change for field 1, field2, 3 and 4 while mapping them
Regards,
Vikas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
On top of what Vikas replied, here is approach 3 -
1. You can do mapping with segment1 to row putting a logic in Graphical mapping if field2 = AA.
Afterwards, in the sub-parameters it will be one to one mapping for field1, field2 etc..
2. Duplicate row in the target end and put logic to create row as per occurrence of segment1 when field2 is not equals to AA.
In the sub parameter, field1, field2 etc. will be mapped with constant 0 here.
Thanks,
Apu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Apu,
Thank you for your input!
On option 1 I'm having same issue as I told to Vikas: if I send segment1 to row then more rows in target side will be created than the expected one (it is 1 source row per 1 target row).
Option 2 was good idea but I assume it should be having the same issue as the others acording to the tests I've done.
Remember that logic is:
Any comments or help will be really appreciated.
Regards!
Hi,
1. First of all you don't need UDF to solve this requirement
you first need to maps segments to row (both 1 to unbounded)
field 1 -> if segment (exists) AND field2.equalsS("AA") map field1 to field1 else map 0 to field1
You can avoid segment(exists) logic as field2 will exist only if segment exists so the below logic is sufficient,the sam will work for all fields

2. The problem in your approach is you are doing result.addValue() but not doing ResultList.CC to handle contexts, so all values from udf will be coming in same context. else apply splitByValue(eachvalue) after udf
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vikas,
Thanks for your response.
Option 1 will not work because segments1 will not always come as segment is 0..1, and also there may be repetitive segment1 but only 1 row on the source:


So logic here tries to create more than one row when only one must be created.
Regarding option 2, thanks for the advice on the UDF.
| User | Count |
|---|---|
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.