cancel
Showing results for 
Search instead for 
Did you mean: 

SortByKey

shweta_walaskar2
Contributor
0 Kudos

Hi,

I have a requirement where I need to sort a field based on some other field in the same parent segment.

I am using SortByKey function but my problem is,this field is not a mandatory field while the other one is always there.

But if this field is there ,it has to be sorted by the mandatory field.

Hence,if I use SortByKey and this field is absent,my mapping fails.Using exists function to check if field exists before passing it to SortByKey doesnt help.

I am trying to create my own SortByKey which takes care of such fields but I am just lost in coding for hashmaps,can anybody help me in this?

Or do we have a better approach to handle this?

Please let me know.

Thanks.

Best Regards,

Shweta

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI,

Try map with default function.

Source fieldmapwithdefaultremovecontext--sortbykey.

Regards,

Prakasu.M

shweta_walaskar2
Contributor
0 Kudos

Thanks to all who have helped in this issue.

Problem is solved using:

Source fieldmapwithdefaultremovecontext--sortbykey

Regards,

Shweta

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

I am not understanding why with "exists" function you not able to sort the issue. Is your optional field going to appear in your input file in case value is not coming? If thats the scenario then check field with "equals" function with constant [](blank) and then go for a "if" function. Hope it helps you out.

Regards,

Vineetha.

Former Member
0 Kudos

Try this way:

If => field exists => sortby

=> else => ... (mapwithdefault, ....)

former_member181962
Active Contributor
0 Kudos

Hi Shweta,

Can you try using the mapWithDefault function for the field that is not mandatory and pass the output of the mapWithDefault function to the SortWithKey

Regards,

Ravi Kanth Talagana