cancel
Showing results for 
Search instead for 
Did you mean: 

Context change UDF

former_member193466
Participant
0 Kudos

Hi,

I have a requierement that file will be received in the below format.

But in Target structure Header should be populated based on the group of fields "a" and "c" where in "a" field should be uniquely considered. i.e. Header should come 4 times.

Please suggest if this can be achieved through Graphical mapping? if not please help me with the UDF.

Thank you.

<Deatils>
<a>13thNov</a>
<b>23</b>
<c>1.1</c>
<d>101</d>
</Details>
<Deatils>
<a>14thNov</a>
<b>21</b>
<c>1.2</c>
<d>101</d>
</Details>
<Deatils>
<a>14thNov</a>
<b>23</b>
<c>1.1</c>
<d>102</d>
</Details>
<Deatils>
<a>15thNov</a>
<b>23</b>
<c>1.1</c>
<d>101</d>
</Details>
<Deatils>
<a>15thNov</a>
<b>23</b>
<c>1.1</c>
<d>101</d>
</Details>
<Deatils>
<a>16thNov</a>
<b>23</b>
<c>1.1</c>
<d>101</d>
</Details>

Accepted Solutions (1)

Accepted Solutions (1)

former_member184681
Active Contributor
0 Kudos

Hi V R,

Did I get your requirement right, that you need to create one Header for each unique value of field a? If so, use the following mapping:

a -> removeContexts -> splitByValue(Value Change) -> collapseContexts -> Header

Regards,

Greg

former_member193466
Participant
0 Kudos

Hi Greg/Vila/GB,

You got me wrong, sorry for the confusion, hope the below can be more clear.

Below is the Source structure we receive:

In that structure we could see the highlighted rows are 5 with the common values from "d" fields.

But while generating the Header it should be 4 headers for the highlighted based on the count of distinct "a" fields where in the respective "d" fields are same and another header with the "d" field of 102..

So totally from the above, the target structure will have 5 Headers based on "a" field and "d" field.

Please help me out.

Thank you so much.

former_member184681
Active Contributor
0 Kudos

Dear V R,

My solution proposal is still valid after this additional explanation, all you need to do is add concat at the beginning, as follows:

a, b -> concat (separator e.g. "_") -> removeContexts -> splitByValue(Value Change) -> collapseContexts -> Header

Depending on whether your input is already sorted or not, you might have to sort it yourself, in addition to the logic above.

Regards,

Greg

former_member184720
Active Contributor
0 Kudos

a, d -> concat (separator e.g. "_")

Answers (1)

Answers (1)

iaki_vila
Active Contributor
0 Kudos

Hi VR

You can use the function formatByExample but when you map the a field you should put before splitbyvalue the function sort following this example:Stefan Grube's blog 

Regards.

former_member193466
Participant
0 Kudos

Hi Vila,

No It is not working with that..the Header should also form based on the contexts.

If we use sort then it will be sorted out simply and will give unexpected result.

Please let me know is there any other way to get this done.

Thank you.

iaki_vila
Active Contributor
0 Kudos

Hi VR,

Could you share what would be the target XML with source example that you have shared?

Regards.

gagandeep_batra
Active Contributor
0 Kudos

have you triyed with

sortby ->splitbyvalueChange->collapscontext>

Regards

GB