static void importCustomDimensionfromCSV(Args _args) // Costcentre,Department,Business Unit
{
CommaTextIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
DimensionAttribute dimAttr;
DimensionAttributeDirCategory dimAttrCategory;
DimensionFinancialTag dimFinancialTag;
Name _name;
DimensionValue _value;
Description _desc;
FileName fileName;
#File
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
csvFile = new CommaTextIo(dfFileName.value(), 'r');
csvFile.inFieldDelimiter(',');
ttsBegin;
while (csvFile.status() == IO_Status::Ok)
{
readCon = csvFile.read();
_name = conPeek(readCon,1); //"CustomDimensionName"
_value = conPeek(readCon,2); //"CustomDimensionValue"
_desc = conPeek(readCon,3); //"CustomDimensionDescription"
dimAttr = DimensionAttribute::findByName(_name);
select dimAttrCategory where dimAttrCategory.DimensionAttribute == dimAttr.RecId;
if(dimAttrCategory)
{
select dimFinancialTag where dimFinancialTag.FinancialTagCategory == dimAttrCategory.DirCategory
&& dimFinancialTag .Value == _value;
if (!dimFinancialTag)
{
dimFinancialTag.Description = _desc;
dimFinancialTag.Value = _value;
dimFinancialTag.FinancialTagCategory = dimAttrCategory.DirCategory;
dimFinancialTag.insert();
}
}
}
ttsCommit;
}
}
{
CommaTextIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
DimensionAttribute dimAttr;
DimensionAttributeDirCategory dimAttrCategory;
DimensionFinancialTag dimFinancialTag;
Name _name;
DimensionValue _value;
Description _desc;
FileName fileName;
#File
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
csvFile = new CommaTextIo(dfFileName.value(), 'r');
csvFile.inFieldDelimiter(',');
ttsBegin;
while (csvFile.status() == IO_Status::Ok)
{
readCon = csvFile.read();
_name = conPeek(readCon,1); //"CustomDimensionName"
_value = conPeek(readCon,2); //"CustomDimensionValue"
_desc = conPeek(readCon,3); //"CustomDimensionDescription"
dimAttr = DimensionAttribute::findByName(_name);
select dimAttrCategory where dimAttrCategory.DimensionAttribute == dimAttr.RecId;
if(dimAttrCategory)
{
select dimFinancialTag where dimFinancialTag.FinancialTagCategory == dimAttrCategory.DirCategory
&& dimFinancialTag .Value == _value;
if (!dimFinancialTag)
{
dimFinancialTag.Description = _desc;
dimFinancialTag.Value = _value;
dimFinancialTag.FinancialTagCategory = dimAttrCategory.DirCategory;
dimFinancialTag.insert();
}
}
}
ttsCommit;
}
}
No comments:
Post a Comment