This is a job I had in my kitty. Thought I just blog it before I lose it. It imports custom dimensions. I had to write one up
Code:
static void naxax_importCustomDimensions(Args _args)
{
//dialog
AsciiIO asciiIO;
Filename filename;
NoYesId skipFirstLine;
Container line;
Dialog dialog;
DialogField dialogFileName, dialogSkipFirstLine, dialogCountryRegionId;
//values
DimensionFinancialTag dimensionFinancialTag;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
RefRecId categoryRecid;
Name name;
DimensionValue dimValue;
Description description;
dialog = new Dialog("Import custom dimension values");
dialogFileName = dialog.addField(extendedTypeStr(Filenameopen), "File name");
dialogSkipFirstLine = dialog.addField(extendedTypeStr(NoYesId), "Skip first line");
if (dialog.run())
{
filename = dialogFileName.value();
skipFirstLine = dialogSkipFirstLine.value();
}
asciiIO = new AsciiIO(filename, 'R');
if (!asciiIO || asciiIO.status() != IO_Status::Ok )
{
throw error (strfmt("@SYS19312",filename));
}
asciiIO.inRecordDelimiter('\r\n');
asciiIO.inFieldDelimiter(',');
if (skipFirstLine)
line = asciiIO.read();
ttsAbort;
ttsBegin;
while (asciiIO.status() == IO_status::Ok)
{
line = asciiIO.read();
if (line)
{
name = conpeek(line,1);
dimValue = conpeek(line,2);
description = conpeek(line,3);
dimensionAttribute = DimensionAttribute::findByName(name);
if (dimensionAttribute)
{
categoryRecid = dimensionAttribute.financialTagCategory();
if (categoryRecid)
{
dimensionFinancialTag = DimensionFinancialTag::findByFinancialTagCategoryAndValue(categoryRecid, dimValue,true);
if(!dimensionFinancialTag)
{
dimensionFinancialTag.clear();
dimensionFinancialTag.Value = dimValue;
dimensionFinancialTag.Description = description;
dimensionFinancialTag.FinancialTagCategory = categoryRecid;
dimensionFinancialTag.insert();
}
else
{
dimensionFinancialTag.Description = description;
dimensionFinancialTag.update();
}
}
else
{
error(strFmt("Dimension %1 is not a custom dimension", name));
}
}
else
{
error(strFmt("Cannot find dimension name %1", name));
}
}
}
ttsCommit;
}
- Get link
- X
- Other Apps