cancel
Showing results for 
Search instead for 
Did you mean: 

UDF Help

former_member10771
Active Participant
0 Kudos

HI,

I have a scenario as below.

I get four values from the input and are compared to a constant value each . Based on this the value needs to be passed to the result. I know this is possible using mapping functions but some how it is giving me some error.Now I want to use a UDF for this.I have written the below UDF but it does not work and gives me error

if ((i==1) || (j==B)) && ((i==2) || (j==D)) {

result.addValue( ' X ' );

}

else {

result.Value( 'Y");

}

Can anyone please provide the correct inputs afor this one.

Error is incompatible types found : char and operator && cannot be applied to java.lang.String[],java.lang.String[]

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Amit,

You can use this mapping:


                                    constant: X \
                                                 \                           
  i --> equalsS------>   or  -----> and --> ifThenElse --> target
constant:1 /            /            /           /
                       /            /constant:Y /            
  j --> equalsS ----> /            /
constant:B /                      /
                                 /
  i --> equalsS------>   or --> /
constant:2 /            /
                       /                               
  j --> equalsS ----> /
constant:D /

Hope this helps,

Answers (6)

Answers (6)

Shabarish_Nair
Active Contributor
0 Kudos

Note all input that comes into the UDF is treated as a string in version < PI 7.1

so you code is

if ((i==1) || (j==B)) && ((i==2) || (j==D)) {
result.addValue( ' X ' );
}
else {
result.Value( 'Y");
}

Now assuming that i and j are your input fields;

if its a simple UDF then;

your code sud be

if ((i.equals("1") || (j.equals("B")) && ((i.equals("2") || (j.equals"D")) {
return("X");
}
else {
return("Y");
}

if an advanced UDF then, you will have to introduce a for loop through loop through all the context values.

sabyasachi_mohapatra3
Participant
0 Kudos

Hi Amit

try this

if ((i==1) || (j.equals(B))) && ((i==2) || (j.equals(D))) {

result.addValue( ' X ' );

}

else {

result.Value( 'Y");

}

Former Member
0 Kudos

> else {

> result.Value( 'Y");

> }

You have to use

result.addValue( "Y");

in double quotes.

Regards

former_member10771
Active Participant
0 Kudos

Hi

It gives me the following error.

operator == cannot be applied to java.lang.String[],char if ((a =='1') && (b =='B'))

Looks like not able to interpret string. Can some one send me as to how this code needs to be modified

siddhesh_pathak4
Contributor
0 Kudos

ok check ,

if ((a.equals('1')) && (b.equals('B'))

former_member10771
Active Participant
0 Kudos

if ((i==1) || (j.equals(B))) && ((i==2) || (j.equals(D))) {

Some issue with the bracket placement. Rest is working fine.

siddhesh_pathak4
Contributor
0 Kudos

Hello,

i and j are integers as per my understanding. if it is so then i think B and D are the inputs. Check if the input type is string or int.

If it is string the please collect this value into an integer variable.

like int k = Integer.parseInt(B) ; check the conditions with K.

Let us know if you still have the problem.

jyothi_anagani
Active Contributor
0 Kudos

Hi,

Give if Condition like

if ((i=='1') || (j=='B')) && ((i=='2') || (j=='D')) {

result.addValue( ' X ' );

}

else {

result.Value( 'Y");

}

and try..

Thanks.

santhosh_kumarv
Active Contributor
0 Kudos

Hi Amit,

Check the Parenthesis in the IF condition.

Thanks,

SaNv...