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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

C# code to create General Journal with default Dimension not working

(0) ShareShare
ReportReport
Posted on by 10

I have created application to post General Journal with default Dimension on AX system using service. But code not working and not posting any entry.

The Code that i have done for Default Dimension is as below.

AxdType_DimensionAttributeValueSet defaccount = new AxdType_DimensionAttributeValueSet();
AxdType_DimensionAttributeValue difdimValue1 = new AxdType_DimensionAttributeValue();
difdimValue1.Name = "Employees";
difdimValue1.Value = DefaultDimensionEmployees;

AxdType_DimensionAttributeValue difdimValue2 = new AxdType_DimensionAttributeValue();
difdimValue2.Name = "Location";
difdimValue2.Value = DefaultDimensionLocation;

defaccount.Values = new AxdType_DimensionAttributeValue[2] { difdimValue1, difdimValue2 };
//journalLine.DefaultDimension = defaccount;

journalLine.DefaultDimension = defaccount;

When i am trying to post this, 'i received Object reference not set to an instance of an object.'

Can anyone tell me what is wrong in above code?

Waiting for reply,

Momin

I have the same question (0)
  • nmaenpaa Profile Picture
    101,166 Moderator on at

    Could you please use "Use rich text formatting" -> "Insert" -> "Code" when you share your code so that it's easier to read? Thanks!

    Your code doesn't seem to do posting here. Do you get the exception when posting, or when running the code that you shared?

    If the error comes from something that you didn't yet share, could you please consider sharing the code that fails? Also letting us know which line in the code fails would be useful. Thanks!

    By the way, you say that you get error "Object not set to an instance of an object". But you just posted another question asking how to get error message from your AX service to your C# code (community.dynamics.com/.../how-to-get-error-log-from-ax-after-posting-through-c).

    So, are you already getting this error message into your C# code or not?

  • WillWU Profile Picture
    22,363 on at

    Hi Maisamali Momin,

    This error means that you are call a method or access a property on a null object.Please show your complete code.

    AThere are many methods you can use to achieve your requirement.

    Do you have to do it with C#?

    Using DimensionAttributeValueSetStorage class in X++,  this is a simpler and more general method.

    community.dynamics.com/.../get-default-financial-dimension-values-through-x-code

  • Maisamali Momin Profile Picture
    10 on at

    Hi Will WU,

    We are using the same code to post jv on AX system, which is working fine, but only when we are using default dimention its now working.

    We are using C#.

    Here is code with function.

    PostJV.txt

  • nmaenpaa Profile Picture
    101,166 Moderator on at

    Did you already find out which line in your code is causing the exception?

    You could also try to debug the AX code to get more details.

  • udaY-ch Profile Picture
    5,173 on at

    HI,

    try this code, I have used this code to the defaultDimension to populate from C#. I just sent you the dimension code since you said, the code was working fine before initializing default dimension

     FYI ServiceReference is using POCDocService.ServiceReference;

    ServiceReference.AxdType_DimensionAttributeValue dimCostCenter = new ServiceReference.AxdType_DimensionAttributeValue();
    dimCostCenter.Name = "CostCenter";
    dimCostCenter.Value = "1473";
    
    ServiceReference.AxdType_DimensionAttributeValueSet valueSet = new ServiceReference.AxdType_DimensionAttributeValueSet();
    valueSet.Values = new ServiceReference.AxdType_DimensionAttributeValue[1] { dimCostCenter };
    inventJournalTrans.DefaultDimension = valueSet;

    Uday

  • Maisamali Momin Profile Picture
    10 on at

    Hi,

    We are getting exception at line ,

    gjsClient.create(context, journal);

  • Maisamali Momin Profile Picture
    10 on at

    Thanks Mr. Uday,

    I have already tried this code like,

    AxdType_DimensionAttributeValueSet defaccount = new AxdType_DimensionAttributeValueSet();
    
    AxdType_DimensionAttributeValue difdimValue1 = new AxdType_DimensionAttributeValue();
    difdimValue1.Name = "Employees";
    difdimValue1.Value = DefaultDimensionEmployees;
    
    AxdType_DimensionAttributeValue difdimValue2 = new AxdType_DimensionAttributeValue();
    difdimValue2.Name = "Location";
    difdimValue2.Value = DefaultDimensionLocation;
    
    defaccount.Values = new AxdType_DimensionAttributeValue[2] { difdimValue1, difdimValue2 };
    journalLine.DefaultDimension = defaccount;

    but not working.

  • nmaenpaa Profile Picture
    101,166 Moderator on at

    Hi Maisamali,

    could you please use "Use rich text formatting" -> "Insert" -> "Code" when you share your code so that it's easier to read? Thanks!

  • Maisamali Momin Profile Picture
    10 on at

    Sure.

    thanks

  • udaY-ch Profile Picture
    5,173 on at

    hi

    Did you solve the problem ?

    Uday

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans