Monday, June 3, 2013

How to create Inventory Dimension in AX 2012 using X++ Code

InventDimId createInventDim(ItemId                       _itemId,
                                   InventBatchId                _inventBatchId,
                                   WMSLocationId                _wmsLocationId,
                                   WMSPalletId                  _wmsPalletId,
                                   InventSerialId               _inventSerialId,
                                   InventLocationId             _inventLocationId,
                                   EcoResItemConfigurationName  _configId,
                                   EcoResItemSizeName           _inventSizeId,
                                   EcoResItemColorName          _inventColorId,
                                   InventSiteId                 _inventSiteId
                                   )
{
    InventTable item = InventTable::find(_itemId);
    InventDim   inventDim;
    ;
    #InventDimDevelop
    inventDim.InventBatchId     = _inventBatchId;
    inventDim.wmsLocationId     = _wmsLocationId;
    inventDim.wmsPalletId       = _wmsPalletId;
    inventDim.InventSerialId    = _inventSerialId;
    inventDim.InventLocationId  = _inventLocationId;

    if(item.configActive())
    {
        inventDim.ConfigId          = _configId;
    }
    if(item.sizeActive())
    {
        inventDim.InventSizeId      = _inventSizeId;
    }
    if(item.colorActive())
    {
        inventDim.InventColorId     = _inventColorId;
    }
    inventDim.InventSiteId      = _inventSiteId;
    inventDim.initFromInventLocation(inventDim.inventLocation());
    inventDim = InventDim::findOrCreate(inventDim);
    return inventDim.InventDimId;
}

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;
}

Friday, March 1, 2013

SysOperationProgress - using progress bar in operation

SysOperationProgress is a class to use operation progress indicator
find the below sample code for an example:

static void SysOperationProgress_PrimeNumber(Args _args)
{
#avifiles
boolean checkPrime,_showProgess = true;
SysOperationProgress progressBar = new SysOperationProgress();//
int counter,out;
;
counter = 1;
out = 1000;
while(counter < out)
{
checkPrime = ((counter mod 2)!=0 && (counter mod 3) !=0);
if(checkPrime)
{
info(strfmt("its a prime number %1",counter));
}
progressBar.setCaption(strfmt("Generating the prime number for %1",counter));
progressBar.setAnimation(#aviUpdate);//#AviFindFile);
progressBar.setText(strfmt("Processing %1 out of %2",counter,out));
counter++;
}
}

Issue with Compare Tool - Ax 2009

Error :
The specified COM object does not have an object attached.
Object 'COMDispFunction' could not be created.

If you ever come across this error while trying to open the compare tool, the problem is with the "insertHTML2Document" method of 'SysHelp' class,  To avoid this error, make sure no code is modified in this class.

Thanks
Huffff, Successfully wrote my first post.. :-)