Hello guys,
So i've been asked to write an X code which imports Financial Dimensions (Dimension Attribute) and their values (DimensionFinancialTag) from an Excel file, the code i wrote successfully adds values to an existing Fianacial Dimension (created manually via the form) but if the Financial Dimension does not exist it has to create a new one, which it did apparently, but it couldnt somehow add values to this newly created FinancialDimension. I concluded that my code isnt creating it right. I couldnt find any solution, I tried debugging the whole process but it was too complicated. This is the code I wrote, hopefully someone could find my mistake or could recommend an existing method (Standard) that rightly creates a Financial Dimension.
Thank you guys so much.
//MAN--27/01/2020
static void HMCImportDimensionsFinancieres(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row=1;
Dialog dialog;
DialogField dialogField;
Filename filename;
DimensionAttribute _dimensionAttribute;
DimensionFinancialTag _dimensionFinancialTag;
DimensionAttributeDirCategory _dimensionAttributeDirCategory;
DimensionValue _dimensionValue;
Description _description;
Name _name;
RecId _financialTagGategoryRecId;
int nb_dim,nb_val;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
dialog = new Dialog("FileOpen");
dialogField = dialog.addField(extendedTypeStr(FilenameOpen),"File Name");
dialog.run();
if (dialog.run())
{
filename = dialogField.value();
}
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File Cannot Be Found");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
ttsBegin;
row ;
_name = cells.item(row, 1).value().bStr();
_dimensionValue = num2str(cells.item(row, 3).value().double(),0,0,0,0);
_description = cells.item(row, 4).value().bStr();
_dimensionAttribute = DimensionAttribute::findByName(_name);
if(!_dimensionAttribute)
{
_dimensionAttribute.Name = _name;
_dimensionAttribute.BackingEntityType = tableNum(DimensionFinancialTag);
_dimensionAttribute.ViewName = 'DimensionFinancialTag' ;
_dimensionAttribute.insert();
nb_dim ;
}
_dimensionAttribute = DimensionAttribute::findByName(_name);
_financialTagGategoryRecId = _dimensionAttribute.financialTagCategory();
_dimensionFinancialTag = DimensionFinancialTag::findByFinancialTagCategoryAndValue(_financialTagGategoryRecId,_dimensionValue,true);
if((!_dimensionFinancialTag)&&(!_financialTagGategoryRecId))
{
_dimensionFinancialTag.clear();
_dimensionFinancialTag.Description = _description;
_dimensionFinancialTag.Value = _dimensionValue;
_dimensionFinancialTag.FinancialTagCategory = _financialTagGategoryRecId;
if(_dimensionFinancialTag.validateWrite())
{
_dimensionFinancialTag.insert();
nb_val ;
}
}
ttsCommit;
type = cells.item(row 1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
info(strFmt('%1 dimensions ont été importées',nb_dim));
info(strFmt('%1 valeurs de dimension ont été importées',nb_val));
}dimension-alger.xlsx