cancel
Showing results for 
Search instead for 
Did you mean: 

retrieving data using if conditions checking input field as seperat

Former Member
0 Kudos

I have requirement like this,

there is only one input field.

if a person enters last name it must give list of names avalilable with this last name from BAPI

else

if a person enters lastname,firstname it must retrieve only names matching this criteria

I used this code . so i can able to retrieve lastname, firstname in the table

String name = wdContext.currentContextElement().getLName();

String fullname[]=name.split(",");

input.setLastname_M(fullname[0]);

input.setFstname_M(fullname[1]);

but when i use only last name. I am receiving an error

"java.lang.ArrayIndexOutOfBoundsException: 1 "

Plz give me some " if else conditions" while there is seperator (',') is given in input field.

it check the seperator

Please help me with this code

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks for all immediate replies

Former Member
0 Kudos

Hi anitha,

Use this code,

String name = wdContext.currentContextElement().getLName();

if(name != null && name.indexOf(",") > -1)

{

input.setLastname_M(name.substring(0, name.indexOf(","));

input.setFstname_M(name.substring(name.indexOf(",") + 1);

}

else if(name != null && name.indexOf(",") < 0)

{

input.setLastname_M(name);

}

Regards,

Sunaina Reddy T

Former Member
0 Kudos

HI Anitha,

When you are entering only the last name the array size will be one.i.e, there is only fullname[0], won't be fullname[1].

But u r setting " input.setFstname_M(fullname[1]);" That is why it is giving ArrayIndexOutofbounda exception.So when u r assigning names to input fileds , check the length of the array.

if(fullname.length>1)

{

input.setLastname_M(fullname[0]);

input.setFstname_M(fullname[1]);

}

else{

input.setLastname_M(fullname[0]);

input.setFstname_M(null);// give if the Bapi required some value in it.Otherwise ignore it.

}

Regards,

srikanth

Former Member
0 Kudos

Hi Anitha,

this is no WD problem, you just have to understand java Arrays.

Do the following:

String fieldValue = <here you get the Text from the GUI>

String parts[] = fieldValue.split(",",2); // the 2 is the maximum of parts, image someone entering "Name, Name, Name, Name" ...

now you check the length of the array, if it is 1, you just have the Lastname, if it is 2, you have first- and lastname:

if (parts.length ==1) {

input.setLastname(parts[0]);

} else {

input.setLastname(parts[0]);

input.setFirstname(parts[1]);

}

Hope that helps

Jan