Update physical dimension of an item Ax2012 – CSV import

There are two ways where we can update the physical dimensions of an item in Ax2012.
Option 1:
1
Option 2:
2
Option 1 updates the fields in invent table . But it doesn`t reflect the changes in option 2 form (Manage Inventory -> Physical dimensions).
If either width or depth or height is changed , Volume calculation has to be done manually.
So this option is not the ideal way to update the physical dimensions fields.
Option2 addresses all the issues in former approach. Changes done on this table would reflect in Invent table fields . Volume calculations are taken care as well.
Thus , apt way to modify the values of physical dimensions will be from the path PIM-> Released Products -> Manage Inventory -> Physical dimensions.
Code snippet is given below to import the fields using csv.
static void AE_ImportItemsPhysicalDimensions(Args _args)
{
Dialog dialog = new Dialog();
DialogField dialogField;
AsciiIo importFile;
str filePath,fileNameOnly;
filetype type;
container record;
str Delimiter = “,”;
int totalRecords, updates;

InventTable inventTable;
WHSPhysDimUOM WHSPhysDimUOM;

dialogField=dialog.addField(extendedTypeStr(FilenameOpen),”Select File”,”Select file to import”);
dialog.caption(“Import Items weight and size”);
dialog.filenameLookupFilter([‘csv’,’*.csv’]);
if(!dialog.run())
return;
[filePath, fileNameOnly, type] = fileNameSplit(dialogField.value());
importFile = new AsciiIo(dialogField.value(), ‘R’);
if((!importFile) || (importFile.status() != IO_Status::Ok))
{
warning(“Error in opening import file”);
throw(Exception::Error);
}
importFile.inFieldDelimiter(Delimiter);
if((!importFile) || (importFile.status() != IO_Status::Ok))
{
warning(“Error in opening log file”);
throw(Exception::Error);
}
try
{
ttsbegin;
while(importFile.status() == IO_Status::Ok)
{
record = importFile.read();
if(!record)
break;
totalRecords++;

inventTable = InventTable::find(conPeek(record,1), true);
select forupdate Width, Height, Depth from WHSPhysDimUOM where WHSPhysDimUOM.ItemId == inventTable.ItemId && WHSPhysDimUOM.UOM == ‘Un’;
if(!inventTable)
{
warning(strFmt(“Item %1 doesn’t exist.”,conPeek(record,1)));
}
else
{
updates++;
WHSPhysDimUOM.Width = conPeek(record,3);
WHSPhysDimUOM.Height = conPeek(record,4);
WHSPhysDimUOM.Depth = conPeek(record,5);
WHSPhysDimUOM.update();
}
}
ttscommit;
}
catch(Exception::Error)
{
Throw(Exception::Error);
}
info(strFmt(“Total updated items = %1 out of %2”,updates,totalRecords));
}

Advertisements

About AnithaEswaran

Hello all, Thanks for visiting my blog. I started this blog to share my learning with Ax members . Since I am from technical background, most of my posts would be from X++. Thanks to my mentor and my colleague Romain who guided and helped me in learning many new concepts in Ax. This instilled confidence in me to handle and troubleshoot complex issues. Feedback wrt to my blog entries are most welcome …
This entry was posted in Ax 2012, Dynamics Ax, File Handling, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s