cancel
Showing results for 
Search instead for 
Did you mean: 

Sort different contexts (having multiple values), in ascending order, for the same queue.

amankumarmangla
Explorer
0 Kudos

Hello all,

I have a requirement where I need to sort one queue which contains multiple contexts and each context is having multiple values.

As per attached screenshot, I need to sort the output based on the value that is occurring before '+' symbol and publish the output in ascending order. My output should ideally look like follows:

15112371+98.83

15112371+0.43

.

.

.

15112371+

-Context Change-

15112372+98.84

15112372+0.50

.

.

.

15112372+

Looking forward to your kind inputs.

Best regards,

Aman

amankumarmangla
Explorer
0 Kudos

avinash.avi Could you please help here?

Thanks,

Aman

former_member216164
Participant
0 Kudos

Hi Aman,

Didn't get a chance to open scn on Friday. Did you manage to solve this or still looking for the code?

Thanks,

Avinash B

amankumarmangla
Explorer
0 Kudos

Still looking for it buddy. Requesting kind help.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

former_member216164
Participant

Hi Aman,

Try following

Do a remove context --> sort --> UDF with all values in queue.

CODE:

String s1="";
String s2="";


try{


for(int i=0;i<input.length;i++)
{
		s1=input[i].substring(0,input[i].indexOf("+"));
		s2=input[i+1].substring(0,input[i+1].indexOf("+"));


	if (s1.equals(s2)) 
		{
						result.addValue(input[i]);
		}
		else
		{
						result.addValue(input[i]);
						result.addValue(ResultList.CC);
		}
}




}




catch(Exception e)
{


}


Thanks,

Avinash B

amankumarmangla
Explorer
0 Kudos

Hello Avinash,

Thanks a lot for your inputs. Below is the output that I am getting. LHS is the old output and RHS is the new one. Though the values are getting sorted, the highlighted one is getting missed in the new output. Could you please suggest?

Thanks,

Aman

former_member216164
Participant

Sorry My bad. Try this. It should work fine.

String s1="";
String s2="";


for(int i=0;i<input.length;i++)
{


	if(i!=input.length-1)
	{


		s1=input[i].substring(0,input[i].indexOf("+"));
		s2=input[i+1].substring(0,input[i+1].indexOf("+"));


					if (s1.equals(s2)) 
					{
								result.addValue(input[i]);
					}
					else
					{
								result.addValue(input[i]);
								result.addValue(ResultList.CC);
					}
	}
	else
	{
				result.addValue(input[i]);
	}
}



Thanks,

Avinash B

amankumarmangla
Explorer
0 Kudos

Hello avinash.avi,

Thanks a lot for the update. The logic and code that you have provided are working perfectly fine for below input (LHS) and I am getting RHS as output. This is perfect.

However, this code is not working for the following input. Could you please suggest the changes that needs to be done to this code in order to make it work similar to the above?

Best regards,

Aman

amankumarmangla
Explorer
0 Kudos

Hello Avinash,

Here is the output that I am expecting here:

15112371+CU+

15112371+CR+

15112371+ZN+

15112371+TI+

15112371+MN+0.03

15112371+FE+0.20

15112371+SI+0.43

15112371+MG+0.46

15112371+AL+98.83

- Context Change-

15112372+CU+

15112372+ZN+

15112372+TI+

15112372+CR+0.01

15112372+MN+0.03

15112372+FE+0.19

15112372+MG+0.38

15112372+SI+0.50

15112372+AL+98.84

amankumarmangla
Explorer
0 Kudos

Hello avinash.avi,,

I just realised, even if I do not get a ContextChange, that will serve the purpose for me. Requesting you to kindly suggest on the logic. Below is the input (screenshot) that I am getting and below that is the desired output.

15112371+CU+

15112371+CR+

15112371+ZN+

15112371+TI+

15112371+MN+0.03

15112371+FE+0.20

15112371+SI+0.43

15112371+MG+0.46

15112371+AL+98.83

15112372+CU+

15112372+ZN+

15112372+TI+

15112372+CR+0.01

15112372+MN+0.03

15112372+FE+0.19

15112372+MG+0.38

15112372+SI+0.50

15112372+AL+98.84

Thanks in advance.

-Aman

amankumarmangla
Explorer
0 Kudos

Hello Avinash,

I managed to get the desired output by tweaking the mapping logic and using standard functions. Also, used a substring UDF.

Thanks a ton for your help.

Best regards,

Aman

former_member216164
Participant
0 Kudos

Good to hear Bro..!
Cheers 🙂

Answers (0)