static void DMF_Assets_Dimension_Import(Args _args)
{
Dialog dialog;
DialogField dfFileName;
int noOfRecs = 0;
CommaIO csvFile;
container fileInCon,checkcon;
counter icount,inserted,check,updated,jcount,wcount;
boolean flag=0;
FileName fileName;
AssetBook assetBook;
AssetId assetId;
AssetBookId assetBookId;
Struct struct = new Struct();
container ledgerDimension;
DimensionDefault DimensionDefault,DefaultDim;
String15 DimVal1,DimVal2,DimVal3,DimVal4,DimVal5;
;
inserted = 0;
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
dialog.filenameLookupFilter(["CSV ","*.csv"]);
if (dialog.run())
{
filename = dfFileName.value();
}
csvFile = new CommaIO(filename, 'r');
if (csvFile)
{
while (csvFile.status() == IO_Status::OK)
{
try
{
fileInCon = csvFile.read();
icount++;
if (fileInCon && icount>1)
{
flag = 0;
assetId = conPeek(fileInCon,1);
DimVal1 = conPeek(fileInCon,2);
DimVal2 = conPeek(fileInCon,3);
DimVal3 = conPeek(fileInCon,4);
DimVal4 = conPeek(fileInCon,5);
DimVal5 = conPeek(fileInCon,6);
assetBookId = conPeek(fileInCon,7);
struct.add('BusinessUnit',DimVal1);
struct.add('CostCenter',DimVal2);
struct.add('Department',DimVal3);
struct.add('ItemGroup',DimVal4);
struct.add('Project',DimVal5);
ledgerDimension += struct.fields();
ledgerDimension += struct.fieldName(1);
ledgerDimension += struct.valueIndex(1);
ledgerDimension += struct.fieldName(2);
ledgerDimension += struct.valueIndex(2);
ledgerDimension += struct.fieldName(3);
ledgerDimension += struct.valueIndex(3);
ledgerDimension += struct.fieldName(4);
ledgerDimension += struct.valueIndex(4);
ledgerDimension += struct.fieldName(5);
ledgerDimension += struct.valueIndex(5);
assetBook = AssetBook::find(assetId,assetBookId,true);
if(assetBook)
{
ttsBegin;
// select forUpdate custTable;
DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
assetBook.DefaultDimension = DimensionDefault;
assetBook.update();
updated++;
info(strFmt("The Financial Dimension for AssetId %1 is updated",assetId));
ttsCommit;
}
else
{
//
//Write insert logic here;
//
}
}//if
}//try
catch
{
info(strFmt("Error at line %1",icount));
}
}//while
}//if csv
info(strfmt("%1 records updated out of %2",updated,icount-2));
}//final