Thursday, May 23, 2013

Code to convert word document to pdf


COM wordApplication;
COM wordDocuments;
COM wordDocument;
COM wordRange;
;

wordApplication = new COM("word.application");
wordDocuments = wordApplication.Documents();
wordDocument = wordDocuments.Open("C:\\temp\\SalesOrder Status.docx");
wordDocument.ExportAsFixedFormat("C:\\temp\\Write2PDFTest.pdf", 17);
wordDocument.close();
wordApplication.quit();

Monday, May 20, 2013

Reading Data from Excel file


static void ReadExcel(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
ItemId itemid;
Name name;
FileName filename;

;

application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = “C:\\item.xls”;
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error(“File cannot be opened.”);
}

workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
itemId = cells.item(row, 1).value().bStr();
name = cells.item(row, 2).value().bStr();
info(strfmt(‘%1 – %2′, itemId, name));
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}

Multi Records Selection in AX


To select multiple records that are checked in a form.

void checkSelectedRecords()
{
Student inventLocal;
;
//getFirst method gets all the selected records in the grid
inventLocal = Student_ds.getFirst(true);

while (inventLocal)
{
info(strfmt(“You selected Item %1″,inventLocal.Studentid));
// get the next selected record
inventLocal = Student_ds.getNext();
}
}

void clicked()
{
super();
element.checkSelectedRecords();

//student_ds.checkSelectedRecords();

}
check the buttons property multiselect :: yes or not

Sleep function:


To execute a piece of code after some time we can use the sleep function, in this method we can set a time ….
static void sleep(Args _arg)
{
int seconds = 10;
int i;
;
i = sleep(seconds*1000);
print “job slept for ” + int2str(i/1000) + ” seconds”;
pause;
}