Used this job to load StandardCostPrice into AX 2012 R2
static void StandardCostPriceImportJob(Args _args)
{
InventItemPriceSim priceSim;
InventDim invDim;
FileIOPermission permission;
boolean first = true;
CommaIo commaIo;
FileName fileName = "\\\\Servername\\folder\\subfolder\\Filename.csv";
container readCon;
int i;
str itemNum, costingType, priceType, versionId, site, price, priceUnit, priceCharges,priceQty,IncInUnitPrice,unitId, activateDate;
str color, style, size, configuration;
CostingVersionPriceType costVersionPriceType;
permission = new FileIOPermission (fileName, 'r');
permission.assert();
commaIo = new CommaIo(fileName, 'r');
commaIo.inFieldDelimiter(',');
ttsBegin;
if(commaIo)
{
while(commaIo.status() == IO_Status::Ok)
{
readCon = commaIo.read();
if (readCon)
{
if (first) //To skip header
{
first = false;
}
else
{
//File should contain fields in below sequence
itemNum = conPeek(readCon, 1);
costingType = conPeek(readCon, 2);
priceType = conPeek(readCon, 3);
versionId = conPeek(readCon, 4);
site = conPeek(readCon, 5);
price = conPeek(readCon, 6);
priceUnit = conPeek(readCon, 7);
priceCharges = conPeek(readCon, 8);
priceQty = conPeek(readCon, 9);
IncInUnitPrice = conPeek(readCon, 10);
unitId = conPeek(readCon, 11);
activateDate = conPeek(readCon, 12);
color = conPeek(readCon, 13);
style = conPeek(readCon, 14);
size = conPeek(readCon, 15);
configuration = conPeek(readCon, 16);
invDim.InventSiteId = site;
invDim.InventColorId = color;
invDim.InventStyleId = style;
invDim.InventSizeId = size;
invDim.configId = Configuration;
invDim = InventDim::findOrCreate(invDim);
if(InventTable::find(itemNum))
{
if(!InventItemPriceSim::find(itemNum,versionId,str2Date(activateDate,123),str2enum(costVersionPriceType,priceType),invDim.inventDimId))
{
priceSim.clear();
priceSim.ItemId = itemNum;
priceSim.PriceType = str2enum(costVersionPriceType,priceType);
priceSim.VersionId = versionId;
priceSim.Price = str2num(price);
priceSim.PriceUnit = str2int(priceUnit);
priceSim.UnitID = unitId;
priceSim.PriceQty = str2num(priceQty);
priceSim.InventDimId = invDim.InventDimId;
priceSim.PriceAllocateMarkup = NoYes::Yes;
priceSim.FromDate = str2Date(activateDate, 123);
priceSim.insert();
i++;
info(strFmt("Imported std cost is %1", itemNum));
}
}
}
}
}
info(strFmt("total number of std imported is %1", i));
}
ttsCommit;
}