Adding a Document Dimension in code

Dave_SDave_S Member Posts: 17
Hi,

Im looking for some help. I am trying to add a dimension to a Purchase Invoice or Credit Memo automatically. The dimension value is created and attached to a new field ive added to the Accounting Period GB table and it holds the budget period i.e. 0906. The dimension period code is obtained by reading the accounting gb period table to find the correct period based on the order posting date.

Ive looked at how the default dimensions are added in code but cannot see how to add the new dimension i have created.

Does anyone have any example code of how to add dimensions?

Thanks
Dave

Answers

  • David_CoxDavid_Cox Member Posts: 509
    You need the "Dimension Code" as well as the "Dimension Value Code" to create the entry, and if it already exists decide if you want to replace it (Modify or Error).
    IF AccPeriod."My Dimension Value" <> '' THEN BEGIN
       GLSetup.GET;
       GLSetup.TESTFIELD("Shortcut Dimension 4 Code");
       DocDims.INIT;
       DocDims."Table ID" := DATABASE::"Purchase Header";
       DocDims."Document Type" := "Purchase Header"."Document Type";
       DocDims."Document No." :=  "Purchase Header"."No.";
       DocDims."Line No." := 0;
       DocDims."Dimension Code" := GLSetup."Shortcut Dimension 4 Code";
       DocDims.VALIDATE("Dimension Value Code",AccPeriod."My Dimension Value");
       IF NOT DocDims.INSERT THEN
         DocDims.MODIFY;
    END;
    

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • Dave_SDave_S Member Posts: 17
    Thanks David! It worked perfect! i think i was over complicating things in my head :roll:
  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV 2009' forum to 'NAV/Navision' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.