on 07-29-2009 12:57 PM
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
Thanks for all immediate replies
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.