Better way to insert Dimension Set ID from AL code

samantha73
Member Posts: 118
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;
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;

0
Answers
-
Simply validating Shortcut(Global)DimensionX field does the trick.0
-
Hey i think this will work for you.
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);
0 -
Thanks, heaps for the suggestion and I could get ideas on a better way to manage Dim values. Now for the code itself , I don't think BC has the method
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 code0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions