#NAVdevTips 11: Default Dimensions – small change but important
Have you ever built new master table similar to Customer or Vendor? Maybe not every day but probably you did. So you know that Default Dimensions are something which is a must in such case.
How you handle Default Dimensions in NAV 2017?
Not so easy on first look. Let’s prepare some example first. I created new table Person and page Person Card for which we need to add dimensions.
But what happed if I wanted to open Dimensions? I got the error that table ID must not be 50001 in Default Dimension Table.
To add Default Dimensions we need to do one additional thing. New event subscriber must be created which will have only one line adding our table to list of allowed tables.
How you handle Default Dimensions in NAV 2018 and Business Central?
Let’s check what is happening behind the scene. In Codeunit 408 in NAV 2017 there was function with listed all tables to which default dimension were allowed. And at the end of it you could see our event OnAfterSetupObjectNoList.
In NAV 2018 and Business Central we would not see this anymore. Instead of it we will get new function DefaultDimObjectNoList. It has got two other functions. First one DefaultDimObjectNoWithoutGlobalDimsList contain similar list to this which you can see in 2017 version. But as on below screen it has only few lines. Also as you can notice there is no integration event which we used.
So how system knows that you can add Default Dimension to other tables?
There is a second function which finds all tables which have field with name Global Dimension. It is called DefaultDimObjectNoWithGlobalDimsList.
From this function you can notice few things
1st
You do not need anymore to use event OnAfterSetupObjectNoList to allow users add default dimension – simply add fields Global Dimension 1 and Global Dimension 2. Of course in such case you need to handle Global Dimension choose and you will anyway need to handle one additional event to change global dimensions on your card when changing default dimension. For this you can use OnAfterUpdateGlobalDimCode event present in table Default Dimension (352).
2nd
Still there is a integration even OnAfterSetupObjectNoList means if you do not like the idea with Global Dimensions fields you can use the same pattern as in NAV 2017 – however I would recommend you to use Global Dimensions as in most cases you should use the same logic as in standard NAV or Business Central.
3rd
When creating any table which does not need Default Dimensions either add field Dimension Set ID field to a table (for example document header or line) or not use Global Dimension name of field (for example in any of setup tables)
4rd
This function skips two tables – first one General Ledger Setup makes sense from beginning. It is setup table which set the Dimension Shortcuts. Second is Job Task and this is because of exception. This table for dimensions use Job Task Dimension table.
Hi, i’m adding default dimensions to a custom table in business central. I’m not being able to figure out where do I call this event ‘OnAfterUpdateGlobalDimCode’ so that my table gets added to default dimension table ? Can you please help…
Hi, you need to create subscriber to the event which is in table Default Dimension. Check the source for the table and it is in at the end of function: UpdateGlobalDimCode. In your subscriber you need to have similar code to this one which is for Work Center:
local procedure UpdateWorkCenterGlobalDimCode(GlobalDimCodeNo: Integer; WorkCenterNo: Code[20]; NewDimValue: Code[20])
var
WorkCenter: Record "Work Center";
begin
if WorkCenter.Get(WorkCenterNo) then begin
case GlobalDimCodeNo of
1:
WorkCenter."Global Dimension 1 Code" := NewDimValue;
2:
WorkCenter."Global Dimension 2 Code" := NewDimValue;
end;
WorkCenter.Modify(true);
end;
end;
Hi Kris,
Thank you for getting in touch, I have created subscriber to the event ‘OnAfterUpdateGlobalDimCode’: but i’m not sure where to call it…..Can you share some more information ?
[EventSubscriber(ObjectType::Table, database::”Default Dimension”, ‘OnAfterUpdateGlobalDimCode’, ”, false, false)]
local procedure OnAfterUpdateGlobalDimCode(GlobalDimCodeNo: Integer; TableID: Integer; AccNo: Code[20]; NewDimValue: Code[20])
var
Subscription: Record “MDCSM Subscription”;
begin
if Subscription.Get(AccNo) then begin
case GlobalDimCodeNo of
1:
Subscription.”Global Dimension 1″ := NewDimValue;
2:
Subscription.”Global Dimension 2″ := NewDimValue;
end;
Subscription.Modify(true);
end;
end;
You just need to create an event in some codeunit it should be called automatically.
Just add in the beginning:
if TableID = Database::”MDCSM Subscription” then …
Hi Kris,
Thank you very very much for your help.
I just want to know one more thing, can we only have one dimension for a record ?
because the value of GlobalDimCodeNo is always 1 ? if not, how can I add two dimensions ?
That tricky 🙂 I would need to see more of your code. But there are two global dimension codes
I have just the following code behind action:
action(Dimensions)
{
ApplicationArea = MDCSMPremium;
Caption = ‘Dimensions’;
Image = Dimensions;
Promoted = true;
RunObject = Page “Default Dimensions”;
RunPageLink = “Table ID” = CONST(70329075),
“No.” = FIELD(Code);
}
and event subscriber code:
local procedure OnAfterUpdateGlobalDimCode(GlobalDimCodeNo: Integer; TableID: Integer; AccNo: Code[20]; NewDimValue: Code[20])
var
Subscription: Record “MDCSM Subscription”;
begin
if TableID = Database::”MDCSM Subscription” then
if Subscription.Get(AccNo) then begin
case GlobalDimCodeNo of
1:
Subscription.”Global Dimension 1″ := NewDimValue;
2:
Subscription.”Global Dimension 2″ := NewDimValue;
end;
Subscription.Modify(true);
end;
end;
and code behind two dimension fields in table:
field(40; “Global Dimension 1”; Code[20])
{
CaptionClass = ‘1,1,1’;
Caption = ‘Global Dimension 1 Code’;
TableRelation = “Dimension Value”.Code WHERE(“Global Dimension No.” = CONST(1));
trigger OnValidate()
begin
ValidateShortcutDimCode(1, “Global Dimension 1”);
end;
}
field(41; “Global Dimension 2”; Code[20])
{
CaptionClass = ‘1,1,2’;
Caption = ‘Global Dimension 2 Code’;
TableRelation = “Dimension Value”.Code WHERE(“Global Dimension No.” = CONST(2));
trigger OnValidate()
begin
ValidateShortcutDimCode(2, “Global Dimension 2”);
end;
}
Great Blog.
Through your blog its only possible to add global dimensions but what the 6 shortcut Dimensions?
How can we add them ?
thanks
Update : Ms has added an integration event on DefaultDimObjectNoWithoutGlobalDimsList is it enough to add our custom table ?
Thanks in advance