cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script gives output in Intellij, but in CPI it gives null as a output

SushantShinde
Advisor
Advisor
0 Kudos
798

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();
} 

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
Active Contributor
0 Kudos

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

SushantShinde
Advisor
Advisor

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

Answers (1)

Answers (1)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Sushant,

Please share some input so that we can give some hint on how it works.

Regards,

Sriprasad Shivaram Bhat

SushantShinde
Advisor
Advisor
0 Kudos

Hello Sriprasad,

Have updated the thread with the input data and the output received from IDE, but the same input and script give me a null output in CPI.

BR,

Sushant