class JOB_ImportUOM
{
public static void main(Args _args)
{
UnitOfMeasure _uom;
UnitOfMeasureConversion _uomConvert;
UnitOfMeasureTranslation _uomTranslation;
UnitOfMeasureClass uomClass;
container rec;
TextStreamIo file;
FileUploadTemporaryStorageResult fileUpload;
str fromUnitx,toUnitx,fromUnitNamex,toUnitNamex,classUnitx;
int sep;
int counterx,i;
;
fileUpload = File::GetFileFromUser() as FileUploadTemporaryStorageResult;
file = TextStreamIo::constructForRead(fileUpload.openResult());
try
{
if (file)
{
if (file.status())
{
throw error("@SYS52680");
}
file.inFieldDelimiter('^');
//file.inRecordDelimiter('\r\n');
}
while (!file.status())
{
rec = file.read();
fromUnitx = conPeek(rec, 1);
fromUnitNamex = conPeek(rec, 2);
classUnitx = conPeek(rec, 3);
_uom = UnitOfMeasure::findBySymbol(fromUnitx);
if(!_uom)
{
ttsBegin;
_uom.clear();
_uom.Symbol = fromUnitx;
switch(classUnitx)
{
case 'Length':
uomClass = UnitOfMeasureClass::Length;
break;
case 'Liquid volume':
uomClass = UnitOfMeasureClass::LiquidVolume;
break;
case 'Mass':
uomClass = UnitOfMeasureClass::Mass;
break;
case 'Quantity':
uomClass = UnitOfMeasureClass::Quantity;
break;
default:
uomClass = UnitOfMeasureClass::Quantity;
break;
}
_uom.UnitOfMeasureClass = uomClass;
_uom.IsInventUnit = NoYes::Yes; // custom field
_uom.validateWrite();
_uom.insert();
ttsCommit;
ttsBegin;
_uomTranslation.clear();
_uomTranslation.UnitOfMeasure = _uom.RecId;
_uomTranslation.Description = fromUnitNamex;
_uomTranslation.LanguageId = 'en-us';
_uomTranslation.validateWrite();
_uomTranslation.insert();
ttsCommit;
//info(strFmt("%1 %2 %3 %4",fromUnitx,classUnitx,_uom.Symbol, _uomTranslation.Description));
counterx++;
}
}
info('Import success!');
}
//try
catch
{
error("Error!");
return;
}
info(strFmt("Done! %1 records is imported !",counterx));
}
}