web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)
Answered

How to set dimensions in C/AL

(0) ShareShare
ReportReport
Posted on by

Hi all

I am in the process of making a customized module which has a function that creates a new sales order. This function works fine, but I do not know how to add dimensions to this new sales order via C/AL.

I have setup 3 shortcut dimensions and I would like to add values for those 3 for the sales order.

My first thought was to add 3 records to Dimension set entry table (one for each dimension), but then I found out that I also need to add records to Dimension set tree note table. There must be a an easier way to do this. maybe by using CU 408 - dimension management?

If someone could give me an example of how to do this it would be greatly appreciated 

Thanks

*This post is locked for comments

I have the same question (0)
  • mmv Profile Picture
    11,471 on at

    Hi,

    You may enter the data in the Dimension Set Entry table and call the GetDimensionSetID from DimensionManagement codeunit to get the Dimension Set ID and that can be allocated to the Sales Header or line as the case may be.

    E.g:

    NewDimID := DimMgt.GetDimensionSetID(TempDimSetEntry);

    Where NewDimID is an Integer and TempDimSetEntry is Record of subtype Dimension Set Entry (it has to be a temporary table).

  • Suggested answer
    4BzSoftware Profile Picture
    6,073 on at

    Hi Albor,

    You don't need to touch Dimension Set Tree Node table, it is managed by CU 408.

    Process for your case:

    1. As Mahesh mentioned: insert 3 dimensions into a temporary Dimension Set Entry table.

    2. As Mahesh mentioned: get Dimension Set ID by calling function GetDimensionSetID of CU 408, use the temporary Dimension Set Entry table as parameter.

    3. Update Dimension Set ID of Sales Order with value in step 2.

  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    You have to use the below code 

    Let's assume you want to insert a salesperson dimension

    Where SALESPERSON is Dimension Code and Dimension Value is SK

    DimVal.GET('SALESPERSON','SK');
    TempDimSetEntry.INIT;
    TempDimSetEntry.VALIDATE("Dimension Code",DefDim."Dimension Code");
    TempDimSetEntry.VALIDATE("Dimension Value Code",DefDim."Dimension Value Code");
    TempDimSetEntry."Dimension Value ID" := DimVal."Dimension Value ID";
    TempDimSetEntry.INSERT;
                
    
    To assign this to the created sales order (Assuming you used SalesHeader as the name of the variable for the Sales Header)
            
    SalesHeader."Dimension Set ID" := DimMgt.GetDimensionSetID(TempDimSetEntry);
    SalesHeader.INSERT;
    
    DimVal -- Record of type Dimension Value
    TempDimSetEntry - Record of type Dimension Set Entry (Make sure you set it to temporary)
    


  • Verified answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at
    You can use following code sample
    • dimSetID - Integer
    • recPurLine - Purchase Line
    • recPurDim - Purchase Inv. Dimension
    • recDimSetEntry - Dimension Set Entry
    • recDimSetEntry1 - Dimension Set Entry
    dimSetID := 0; 
    recDimSet.RESET; // This is a temporary record
    IF recDimSet.FINDFIRST THEN REPEAT
       recDimSet.DELETE;
    UNTIL recDimSet.NEXT=0;
    
    IF recPurInvDim.FINDFIRST THEN REPEAT // Record set that has the dim values
       recDimSet.RESET;
       recDimSet.INIT;
       recDimSet.VALIDATE(recDimSet."Dimension Code",recPurInvDim."Dimension Code");
       recDimSet.VALIDATE(recDimSet."Dimension Value Code",recPurInvDim."Dimension Value");
       recDimSet.INSERT;
    UNTIL recPurInvDim.NEXT=0;
    
    dimSetID := 0;
    dimSetID:= cduDimMgt.GetDimensionSetID(recDimSet); // Get the dim set ID
    
    recDimSetEntry1.RESET;
    recDimSetEntry1.SETFILTER(recDimSetEntry1."Dimension Set ID",'%1',dimSetID); // check if the ID is available
    IF recDimSetEntry1.FINDFIRST THEN BEGIN
       
    END ELSE BEGIN
     IF recDimSet.FINDFIRST THEN REPEAT 
        recDimSetEntry.RESET;
        recDimSetEntry.INIT;
        recDimSetEntry.VALIDATE(recDimSetEntry."Dimension Set ID",dimSetID);
        recDimSetEntry.VALIDATE(recDimSetEntry."Dimension Code",recDimSet."Dimension Code");
        recDimSetEntry.VALIDATE(recDimSetEntry."Dimension Value Code",recDimSet."Dimension Value Code");
        recDimSetEntry.INSERT;
     UNTIL recDimSet.NEXT=0;
    END;
    
      recPurLine.RESET;
      recPurLine.SETRANGE(recPurLine."Document Type",recPurLine."Document Type"::Invoice);
      recPurLine.SETRANGE(recPurLine."Document No.",QPurInv.Document_No);
      recPurLine.SETRANGE(recPurLine."Line No.",QPurInv.Line_No);
      IF recPurLine.FINDFIRST THEN BEGIN
         recPurLine."Dimension Set ID" := dimSetID;
         recPurLine.MODIFY;
      END;
    
    recPurDim.RESET;
    recPurDim.SETRANGE(recPurDim."Record Update",TRUE);
    IF recPurDim.FINDFIRST THEN REPEAT
       recPurDim.DELETE;
    UNTIL recPurDim.NEXT=0;
    
    MESSAGE('Process is completed');



  • Community Member Profile Picture
    on at

    Thank you very much for all the replies. The problem is solved!

  • Community Member Profile Picture
    on at

    I also have this problem, thank solved my problem now :)

  • AftabHussain Profile Picture
    5 on at

    What is 

    DefDim?
  • Rafael B. Profile Picture
    715 on at

    @AftabHussain,

    Default Dimension table

  • javedakhtar Profile Picture
    1,751 on at

    Hi Suresh Sir ,

    TempDimSetEntry.VALIDATE("Dimension Code",DefDim."Dimension Code");

    TempDimSetEntry.VALIDATE("Dimension Value Code",DefDim."Dimension Value Code");

    what is the DefDim record??

  • 4BzSoftware Profile Picture
    6,073 on at

    Hi Javed Akhtar,

    It is record 352 Default Dimension.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans