on 2020 Nov 13 2:45 PM
Hello,
I have written a Groovy script for a requirement in CPI, the same script works in intellij giving me the desired output, but fail to produce the same output on CPI. In CPI it gives me a null output. Can someone help here.
My Script
int out = 0;
try {
int i, j, k = 0;
String[] deliveryNO = new String[values.length];
for (i = 0; i < hipos.length; i++) {
for (j = 0; j < i; j++) {
if (hipos[i] != "" && hipos[j] != "" && hipos[i] == hipos[j]) {
break;
}
}
if (i == j && hipos[i] != "") {
deliveryNO[k] = tdobname[i];
k++;
}
}
for (int l = 0; l < values.length; l++) {
values[l] = deliveryNO[l].concat("-").concat(values[l]);
}
for (int m = 0; m < posnr.length; m++) {
for (int n = m; n < hipos.length; n++){
if(hipos[n] != null && !hipos[n].isEmpty())
if (posnr[m].equals(hipos[n].substring(0,6)) && tdobname[m].equals(values[out].substring(0, 10))) {
lfimg[m] = values[out].substring(11);
out++;
break;
}
}
}
for (int l = 0; l < lfimg.length; l++) {
println(lfimg[l]);
}
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
}
Request clarification before answering.
Hi Sushant
Those println statements won't work when the code executes in CPI. They won't fail, but neither will they add their output to the message payload, as you might expect.
If you create string output, you can call message.setBody(yourString) to make that string the message payload.
That works for a single string, by the way. It doesn't append that string to the payload, it replaces the payload with that string. To append iteratively, use something like java.lang.StringBuilder to create the string and then call message.setBody.
Regards,
Morten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Morten,
Thanks for pointing out the 'Println' statement, I am actually adding these values to ResultList.
So I have created a ResultList variable and adding the output values to it and it seems to be working now.
BR,
Sushant
Hello Sushant,
Please share some input so that we can give some hint on how it works.
Regards,
Sriprasad Shivaram Bhat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
30 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.