Conversion of Time in AX2009

/// Try this in your AOT Jobs
 ///
 ///
 ///
 static void timeConversion(Args _arg)
 {
 int s;
 str t, convertedTime;
 ;
// t is a String and we assigned Some Time Value as 11 hr 50 mins and Zero seconds
 t = "11:50:00";
// s is an Integer, and its Converting time value into Seconds value for Example 1hr mean it wil calculate
 // seconds as 3600
 s = str2time(t);
// convertedTime is a String and its Converting the Seconds Value into Time
 convertedTime = time2str(s, Timeseparator::Colon, TimeFormat::Hour24);
info(ConvertedTime);
}
///
Advertisements

Import from Excel file using X++ in AX 2009

//Apply this method in any Button Override Method.
// This method is used to Import the Excel Data to AX Table
//
//
// Excel File Contains 3 Columns which is EquipmentId, Cost, EffectiveDate
// Same way here we have created Code For the particular Three field....
public void ImportData()
{
 SysExcelApplication application;
 SysExcelWorkbooks workbooks;
 SysExcelWorkbook workbook;
 SysExcelWorksheets worksheets;
 SysExcelWorksheet worksheet;
 SysExcelCells cells;
 COMVariantType type;
 System.DateTime ShlefDate;
 FilenameOpen filename;
 dialogField dialogFilename;
 Dialog dialog;
 #AviFiles
 // Progress Bar
 SysOperationProgress progress = new SysOperationProgress(1, NoYes::Yes);
 TestXls _TestXls; // Table name and decleration
 str equipId;
 str cost;
 str effectiveDate;
 int datevalue, row = 0;
 real costr;
 Date dater;
 #Excel
 str COMVariant2Str(COMVariant _cv,
 int _decimals = 1,
 int _characters = 0,
 int _separator1 = 0,
 int _separator2 = 0)
 {
 switch(_cv.variantType())
 {
 case (COMVariantType::VT_BSTR):
 return _cv.bStr();
 case (COMVariantType::VT_R4):
 return num2str(_cv.float(),
 _characters,
 _decimals,
 _separator1,
 _separator2);
 case (COMVariantType::VT_R8):
 return num2str(_cv.double(),
 _characters,
 _decimals,
 _separator1,
 _separator2);
 case (COMVariantType::VT_DECIMAL):
 return num2str(_cv.decimal(),
 _characters,
 _decimals,
 _separator1,
 _separator2);
 case (COMVariantType::VT_DATE):
 return date2str(_cv.date(),
 123,
 2,
 1,
 2,
 1,
 4);
 case (COMVariantType::VT_EMPTY):
 return "";
 default:
 throw error(strfmt("@SYS26908",
 _cv.variantType()));
 }
 return "";
 }
 ;
 dialog = new Dialog("ExcelUpload");
 dialogFilename = dialog.addField(typeId(FilenameOpen));
 dialog.filenameLookupFilter(["@SYS28576",#XLS, "@SYS28576",#XLSX]);
 dialog.filenameLookupTitle("Upload from Excel");
 dialog.caption("Excel Upload");
 dialogFilename.value(filename);
 if(!dialog.run()) Continue reading