on 07-12-2010 3:32 PM
Hi Experts,
I have a JCO connection calling bapi (BAPI_USER_CHANGE) to reset user's password.
I am passing USERNAME, PASSWORD and PASSWORDX. However I am getting an error when password PASSWORD:
"Cannot convert a value of '5qtzsRMVRn' from type java.lang.String to STRUCTURE at field PASSWORD"
I may have to get structure first, but when what to I assign it to?
String newPassword = getRandomString();
try{
JCO.Function bapiUserChange = repository.getFunctionTemplate("BAPI_USER_CHANGE").getFunction();
if(bapiUserChange != null){
JCO.ParameterList userChangeInput = bapiUserChange.getImportParameterList();
JCO.Structure sPassword = userChangeInput.getStructure("PASSWORD");
//sPassword.setValue(newPassword, ????) //what do I assign it to?
userChangeInput.setValue(userId, "USERNAME");
userChangeInput.setValue(newPassword, "PASSWORD"); // this gives an error
userChangeInput.setValue("X","PASSWORDX"); //I know "X" is true, this will give an error too I believe
mConnection.execute(bapiUserChange);
//send E-mail
boolean emailSent = sendEmail(userId, newPassword, "XXX200");
msgMgr.reportSuccess("Password Reset Done");
if(mConnection != null){
mConnection.disconnect();
}
}
}catch(Exception e){
msgMgr.reportException("Could not change password " + e.getMessage(),true);
}
Solved.
String newPassword = getRandomString();
try{
JCO.Function bapiUserChange = repository.getFunctionTemplate("BAPI_USER_CHANGE").getFunction();
if(bapiUserChange != null){
JCO.ParameterList userChangeInput = bapiUserChange.getImportParameterList();
JCO.Structure sPassword = userChangeInput.getStructure("PASSWORD");
JCO.Structure sPasswordx = userChangeInput.getStructure("PASSWORDX");
sPassword.setValue(newPassword, "BAPIPWD");
sPasswordx.setValue('X', "BAPIPWD");
userChangeInput.setValue(userId, "USERNAME");
userChangeInput.setValue(sPassword, "PASSWORD");
userChangeInput.setValue(sPasswordx,"PASSWORDX");
mConnection.execute(bapiUserChange);
//send E-mail
boolean emailSent = sendEmail(userId, newPassword, client);
msgMgr.reportSuccess("Password Reset Done");
disconnectJCO();
}
}catch(Exception e){
msgMgr.reportException("Could not change password " + e.getMessage(),true);
}finally{
disconnectJCO();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rahim,
I am using SAPJco3.x api for reset password by using java client.Should it work with above code by changing classes according to latest Api.Following Code for SAPJCo3.x
public static void resetSAPPwd()
{
String userId="myid";
String newPassword ="mypwd";
try{
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
JCoContext.begin(destination);
JCoFunction bapiUserChange = destination.getRepository().getFunctionTemplate("BAPI_USER_CHANGE").getFunction();
if(bapiUserChange != null){
JCoParameterList userChangeInput = bapiUserChange.getImportParameterList();
JCoStructure sPassword = userChangeInput.getStructure("PASSWORD");
JCoStructure sPasswordx = userChangeInput.getStructure("PASSWORDX");
sPassword.setValue("BAPIPWD",newPassword);
sPasswordx.setValue("BAPIPWD",'X');
userChangeInput.setValue("USERNAME",userId);
userChangeInput.setValue("PASSWORD",sPassword);
userChangeInput.setValue("PASSWORDX",sPasswordx);
bapiUserChange.execute(destination);
System.out.println("SAP Pasw0rd reset done :");
}
}catch(Exception e){
e.getStackTrace();
System.out.println(e.getMessage());
}
}
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
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.