web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

create customer using Services AIF

(0) ShareShare
ReportReport
Posted on by 1,883

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.");
}

}

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    you code is trying to create record only in ENPRO_AX6R3CU9_Live

    there is no where any call to TEST system.

    you are getting record from ENPRO_AX6R3CU9_Live and pushing it in current system.

  • Faqruddin Profile Picture
    1,883 on at

    Thanks shoaib. Could you please help me with piece of  code I wants to push into test system.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    DIXF supports ODBC connection to fetch the data directly, or you could just export the customer entity with DIXF in your source environment, then import it in your target environment. Both solutions are better than writing code for it directly, since customer entity is supported out-of-the-box.

  • Faqruddin Profile Picture
    1,883 on at

    Thanks vilmos. I successfully used before DIXF with ODBC setup for data import. Just for practice I wants to see how standard customer service code will work with odbc connection. Just I'm trying to see how customer automatically reflected to my test enviroment once its created in live DB/environment. For that I wrote above code. But still as per shoaib I need to write code to get the values to my test environment.

  • Vilmos Kintera Profile Picture
    46,149 on at

    All right, for practice scenarios it makes sense. But for real-life applicability it sounded like you are trying to reinvent the wheel :)

    What did you see when you have been debugging it, was there a resultset for your select statement, which has returned values and did your code enter in the while loop?

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    if you are doing this just for practice, I would say you cannot push directly in TEST SQL (bad practice), while standing on LIVE AX.

    you can use an outbound port to push file from Live system to any UNC path. On other end, you can read those exported files using inbound service or x++

  • Vilmos Kintera Profile Picture
    46,149 on at

    He is running that code on Test to pull the data out of Live DB as per my understanding, calling the customer AIF document service locally. This should work fine, if the SQL statement does return values. I did not check what fields should be populated on the service itself, likely there are examples online. Debugging should reveal what the problem is.

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    If he is running code on TEST system, he just need to pass the correct name of Database or ODBC details.

    given that is the scenario, it is really not required to code all these ODBC details. AX is capable to collect ODBC details using current session of user.

  • Faqruddin Profile Picture
    1,883 on at

    No. I set only read permission to live DB using ODBC from Test SQL/environment. Yes I can use Outbound port in live and read it using inbound. Its great and clear. Then what about above create customer service I created to read values from live to test. I test one job its reading values from my live db to my test environment. But I need customer must create in test once its created in live with below connection and the standard customer service class above my post. 

    static void ReadCust(Args _args)
    {
    LoginProperty loginProperty;
    OdbcConnection odbcConnection;
    Statement statement, custStatement;
    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())
    {
    //It is not possible to get field 3 and then 1.
    //Always get fields in numerical order, such as 1 then 2 the 3 etc.
    info (strfmt("(%1) %2: %3, %4", resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4)));

    }

    //Close the connection.

    resultSet.close();
    statement.close();

    }
    else
    {
    error("Failed to log on to the database through ODBC.");
    }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans