Posts

Showing posts from July, 2014

How to Write Data in XML File

Today I will demonstrate you that how to write data in XML file in AX. static void WriteXml(Args _args) { XmlDocument xmlDoc; XmlElement xmlRoot; XmlElement xmlField; XmlElement xmlRecord; XMLWriter xmlWriter; CarTable carTable; DictTable dTable = new DictTable(tablenum(CarTable)); DictField dField; int i, fieldId; str value; #CarsXmlTags ; xmlDoc = XmlDocument::newBlank(); xmlRoot = xmlDoc.createElement(#CarRootNode); while select carTable { xmlRecord = xmlDoc.createElement(#CarRecords); for (i=1; i<=dTable.fieldCnt(); i++) { fieldId = dTable.fieldCnt2Id(i); dField = dTable.fieldObject(fieldId); if (dField.isSystem()) continue; xmlField = xmlDoc.createElement(dField.name()); switch (dField.baseType()) { case Types::Int64 : value = int642str(carTable.(fieldId)); break; case Types::Integer : value = int2str(carTable.(fieldId)); break; default : value = carTable.(fieldId); break; } xmlField.innerText(value); xmlRecord.appendChild(xmlField); } xmlRoot.appe

How to Read Data from XML File

Today I will demonstrate you that how to read data from XML file in AX. static void ReadXml(Args _args) { XmlDocument xmlDoc; XmlElement xmlRoot; XmlElement xmlField; XmlElement xmlRecord; XmlNodeList xmlRecordList; XmlNodeList xmlFieldList; CarTable carTable; DictTable dTable = new DictTable(tablenum(CarTable)); int i, j, fieldId; #CarsXmlTags ; xmlDoc = new xmlDocument(); xmlDoc.load(@"c:\temp\cars.xml"); xmlRoot = xmlDoc.getNamedElement(#CarRootNode); xmlRecordList = xmlRoot.childNodes(); for (i=0; i<xmlRecordList.length(); i++) { carTable.clear(); xmlRecord = xmlRecordList.item(i); xmlFieldList = xmlRecord.childNodes(); for (j=0; j<xmlFieldList.length(); j++) { xmlField = xmlFieldList.item(j); carTable.(dTable.fieldName2Id(xmlField.name())) = xmlField.innerText(); } carTable.insert(); } }

How to write Data in Text File

Today I will demonstrate you that how to write data in text file by using TextIO class in AX. static server void WriteTextFile(Args _args) { TextIo file; FileName filename = @"c:\temp\cars.txt"; CarTable carTable; container con; FileIoPermission permission; #File ; try { permission = new FileIoPermission(filename, #io_write); permission.assert(); file = new TextIo(filename, #io_write); if (!file) throw Exception::Error; file.outRecordDelimiter(#delimiterCRLF); file.outFieldDelimiter(";"); while select carTable { con = connull(); con = conins(con, 1, carTable.CarId); con = conins(con, 2, carTable.CarBrand); con = conins(con, 3, carTable.Mileage); con = conins(con, 4, carTable.Model); con = conins(con, 5, carTable.ModelYear); file.writeExp(con); } } catch(Exception::Error) { error("You do not have access to write the file to the selected folder"); } CodeAccessPermission::revertAssert();   }

How to read Data from Text File

Today I will demonstrate you that how to read data from text file by using TextIO class in AX. static void ReadTextFile(Args _args) { TextIo file; FileName filename = @"c:\temp\cars.txt"; CarTable carTable; container con; FileIoPermission permission; #File ; try { permission = new FileIoPermission(filename, #io_read); permission.assert(); file = new TextIo(filename, #io_read); if (!file) throw Exception::Error; file.inRecordDelimiter(#delimiterCRLF); file.inFieldDelimiter(";"); info("CarId - CarBrand - Mileage – Model - ModelYear"); con = file.read(); while (file.status() == IO_Status::Ok) { info(strfmt("%1 - %2 - %3 - %4 - %5", conpeek(con,1), conpeek(con,2), conpeek(con,3), conpeek(con,4), conpeek(con,5))); con = file.read(); } } catch(Exception::Error) { error("You do not have access to write the file to the selected folder"); } CodeAccessPermission::revertAssert(); }

ODBC Connection for writing data

Today I will demonstrate you that how to establish ODBC connection and use that for writing data in AX. static void WriteOdbc(Args _args)  { OdbcConnection connection; LoginProperty loginProp; Statement statement; str sqlStmt; SqlStatementExecutePermission permission; ; loginProp = new LoginProperty(); loginProp.setServer("SEA-DEV"); loginProp.setDatabase("MicrosoftDynamicsAX"); try { connection = new OdbcConnection(loginProp); } catch { error ("You do not have access to the database specified"); return; } sqlStmt = strfmt("UPDATE dbo.CustTable SET Name='test' WHERE AccountNum='%1' AND Dataareaid='%2'", "1101", "ceu"); permission = new SqlStatementExecutePermission(sqlStmt); permission.assert(); statement = connection.createStatement(); statement.executeUpdate(sqlStmt); CodeAccessPermission::revertAssert(); }

ODBC connection for reading Data

Today I will demonstrate you that how to establish ODBC connection and use that for reading data in AX. static void ReadOdbc(Args _args)  { OdbcConnection connection; LoginProperty loginProp; Statement statement; ResultSet result; str sqlStmt; SqlStatementExecutePermission permission; ; loginProp = new LoginProperty(); // Set the servername and database to the LoginProperty object loginProp.setServer("SEA-DEV"); loginProp.setDatabase("MicrosoftDynamicsAX"); // Check to see if the executing user has access try { // Create a new connection based on the information set in the LoginProperty object connection = new OdbcConnection(loginProp); } catch { error ("You do not have access to the database specified"); return; } // Set the select statement to the string variable sqlStmt = 'SELECT Dataareaid, AccountNum, Name from dbo.CustTable'