Hi All
I am developing an extension to import invoices from an excel file and the excel file contains columns for dimensions. Now I can get this to work but the code is long and looks inefficient. Is there a better way to handle this than below
which is based on blog
https://robertostefanettinavblog.com/2017/06/26/create-new-dimension-id-to-import-dimension-values-from-buffer-table/:
//*dim 1-8
//1***
DimVal.reset;
DimVal.SETFILTER("Dimension Code", '=%1', 'PRODUCT GROUP');
DimVal.SETFILTER(Code, '=%1', SalesImportLine.U_ShortcutDimension1Code);
IF DimVal.FINDFIRST THEN BEGIN
Dim1ValID := DimVal."Dimension Value ID";
TempDimSetEntry.RESET;
TempDimSetEntry."Dimension Code" := 'PRODUCT GROUP';
TempDimSetEntry."Dimension Value Code" := SalesImportLine.U_ShortcutDimension1Code;
TempDimSetEntry."Dimension Value ID" := Dim1ValID;
TempDimSetEntry.INSERT;
end;
//2****
DimVal.reset;
DimVal.SETFILTER("Dimension Code", '=%1', 'CUSTOMER GROUP');
DimVal.SETFILTER(Code, '=%1', SalesImportLine.U_ShortcutDimension2Code);
IF DimVal.FINDFIRST THEN BEGIN
Dim2ValID := DimVal."Dimension Value ID";
TempDimSetEntry.RESET;
TempDimSetEntry."Dimension Code" := 'CUSTOMER GROUP';
TempDimSetEntry."Dimension Value Code" := SalesImportLine.U_ShortcutDimension2Code;
TempDimSetEntry."Dimension Value ID" := Dim2ValID;
TempDimSetEntry.INSERT;
end;
Answers
DimensionTBL - Dimension table
DimVal - Dimension Value table
DimensionTBL.RESET; (I think its not lot dimensions in that table)
DimVal.RESET;
InsertedTRUE:=FALSE; //--You can use it or not(if you inserted you dont need look other dimensions, avoidong loop to end)
IF DimensionTBL.FIND('-') THEN
REPEAT
DimVal.SETRANGE("Dimension Code",DimensionTBL.Code); //Filter all Dimension withhout HARDCODE (best to avoid hardcoding)
DimVal.SETFILTER(Code, '=%1', SalesImportLine.U_ShortcutDimension1Code);
IF DimVal.FINDFIRST THEN BEGIN
Dim1ValID := DimVal."Dimension Value ID";
TempDimSetEntry.RESET;
TempDimSetEntry."Dimension Code" := DimensionTBL.Code; //Dimension Code
TempDimSetEntry."Dimension Value Code" := SalesImportLine.U_ShortcutDimension1Code;
TempDimSetEntry."Dimension Value ID" := Dim1ValID;
TempDimSetEntry.INSERT;
InsertedTRUE:=TRUE; //-- it's fuse for loop
end;
UNTIL (DimensionTBL.NEXT=0) OR (InsertedTRUE = TRUE);
InsertedTRUE. could be NAV only feature
I have recoded without HARDCODING By looking at Gen Led Setup to get dim 1-7. And maybe what I need is a separate code unit to manage dims so it can be triggered from any other code unit ..reusable code