cancel
Showing results for 
Search instead for 
Did you mean: 

UDF - True or Flase

Former Member
0 Kudos

Hi All,

Can anybody please help me with the UDF with the below conditions:

The input is say 'X' and if X is equals to some specific numbers like US0004, US0007, US0009, US0045, US0058, US0065, and US00090 till US0099 then the output should be 1 and any numbers except the mentioned above(like US0001, US0002,and so on) the output should be '2'

Many Thanks,

Smith

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Create Simple UDF type

If( input_field.equals("US0004") || input_field.equals("US0007") || ............)

{

return "1";

}

else return "2";

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Pedro,

I know we could use fix values standard function. But, i have only to check for only one condition for all numbers from 1 to 100 and i thought it would be complex.

@ Unni Krishnan , Venkataramesh , Thanks, I tried your code but unfortunately, it is not working

Any other options please?

Cheers, Smith

Former Member
0 Kudos

Hi Paul,

I changed the Unni code as Stirng temp = st open squarebracket i closesquarebracket..

Whether it is US00090 or US0090. Change according to your values in String array list.

public String checkInput (String value){

String flag = "2";

String[] st = {"US0004", "US0007", "US0009", "US0045", "US0058", "US0065",

"US0090", "US0091", "US0092", "US0093", "US0094", "US0095", "US0096",

"US0097", "US0098","US0099"};

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

String temp = st<i>;

if (temp.equals(value)){

flag = "1";

break;

}

}

return flag;

}

NOw check the code once and let me know if any modifications required.

Regards

Goli Sridhar

pedro_baroni3
Active Contributor
0 Kudos

The function by Unni Krishnan, with a little correction:

public String checkInput (String value){
String flag = "2";
String[] st = {"US0004", "US0007", "US0009", "US0045", "US0058", "US0065", 
"US00090", "US00091", "US00092", "US00093", "US00094", "US00095", "US00096",
"US00097", "US00098","US00099"};

for(int i=0; i < st.length; i++){
String temp = st<i>;
if (temp.equals(value)){
flag = "1";
break;
}
}


return flag;
}

SudhirT
Active Contributor
0 Kudos

Hi Paul,

you can do one thing to get rid of this no. repetition in ur logic.

use substring function to compare d values like

int s = Integer.parInt(a.substring(2,5));

if(s > 4 && s < 90)

return u201C1u201D;

else

return u201C2u201D;

use d substring func according to ur req.

thanks

Former Member
0 Kudos

You could also try something like this

final static String ALLOWED_VALUES = "US0004|US0007|US0009|US0045|US0058|US0065|US00090|US00091|US00092|US00093|US00094|US00095|US00096|US00097|US00098|US00099";

String flag = "2";

if (ALLOWED_VALUES.indexOf(inputValue) != 1) flag = "1";

return flag;

Former Member
0 Kudos

Paul,

Just try the correction Pedro posted,

its stripping off that part when I post :-(...gotta learn how to do it.

Unni

Former Member
0 Kudos

public String checkInput (String value){

String flag = "2";

String[] st = {"US0004", "US0007", "US0009", "US0045", "US0058", "US0065",

"US00090", "US00091", "US00092", "US00093", "US00094", "US00095", "US00096",

"US00097", "US00098","US00099"};

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

String temp = st<i>;

if (temp.equals(value)){

flag = "1";

break;

}

}

return flag;

}

Former Member
0 Kudos

Hi All,

Any help on this would be greatly appreciated as i have stopped my testing only for this UDF.

Cheers,

Smith

pedro_baroni3
Active Contributor
0 Kudos

Hello Paul,

If you do not want to use a UDF, you can use a standard function of the graphical mapping.

The function "Conversion" -> "FixValues" with:

-> Default = 2

-> Key = US0004 and US0007 and ...

-> Value = 1