Dears,
I succesfully made odbc connection to my Live environment database to read customers. Here I'm trying to automatically create customer in my test environment once its created in live environment. For that I use odbc connection to connect external database and use the standard customer service class for customer creation. Now my issue is once customer is created in live database its not reflecting in my test environments. Is there anything wrong with the below code. Please suggest me!
[SysEntryPointAttribute(true)]
public void createCust()
{
CustCustomerService custService;
CustCustomer cust;
CustCustomer_CustTable custTable;
CustCustomer_DirParty dirParty;
CustCustomer_DirParty_DirOrganization dirOrg;
LoginProperty loginProperty;
OdbcConnection odbcConnection;
Statement statement;
ResultSet resultSet;
str sql, criteria;
SqlStatementExecutePermission perm;
;
// Set the information on the ODBC.
loginProperty = new LoginProperty();
loginProperty.setDSN("TEST");
loginProperty.setDatabase("ENPRO_AX6R3CU9_Live");
odbcConnection = new OdbcConnection(loginProperty);
if (odbcConnection)
{
sql = "select CUSTTABLE.ACCOUNTNUM, DIRPARTYTABLE.NAME, CUSTTABLE.CUSTGROUP, CUSTTABLE.CURRENCY from CUSTTABLE INNER JOIN DIRPARTYTABLE ON CUSTTABLE.PARTY = DIRPARTYTABLE.RECID where CUSTTABLE.DATAAREAID = 'enpr'";
//Assert permission for executing the sql string.
perm = new SqlStatementExecutePermission(sql);
perm.assert();
//Prepare the sql statement.
statement = odbcConnection.createStatement();
resultSet = statement.executeQuery(sql);
//Cause the sql statement to run,
//then loop through each row in the result.
while (resultSet.next())
{
custService=CustCustomerService::construct();
cust= new CustCustomer();
custTable = cust.createCustTable().addNew();
custTable.parmAccountNum(resultSet.getString(1));
custTable.parmCustGroup(resultSet.getString(3));
custTable.parmCurrency(resultSet.getString(4));
dirOrg= new CustCustomer_DirParty_DirOrganization();
dirOrg.parmName(resultSet.getString(2));
dirOrg.parmLanguageId("en-us");
custTable.createDirParty().add(dirOrg);
custService.create(cust);
}
//Close the connection.
resultSet.close();
statement.close();
}
else
{
error("Failed to log on to the database through ODBC.");
}
}