Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 64797

Import custom dimensions job [AX 2012]

$
0
0

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

image

Code:
staticvoid 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 = newDialog("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 = newAsciiIO(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;
}


Viewing all articles
Browse latest Browse all 64797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>