Skip to main content

Notifications

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

  • Maisamali Momin Profile Picture
    10 on at
    RE: C# code to create General Journal with default Dimension not working

    Thanks Nikolaos and Uday for your instant support regarding the issue.

    Finally we found that it was data entry mistake from our client side and also have minor changes in code and its resolved.

    Thanks & Regards,

    Momin

  • Martin Dráb Profile Picture
    234,193 Most Valuable Professional on at
    RE: C# code to create General Journal with default Dimension not working

    Please realize that we can't help you if you fail to give us necessary information.

    Which line of code is throwing the exception. And which reference is null?

  • Maisamali Momin Profile Picture
    10 on at
    RE: C# code to create General Journal with default Dimension not working

    We have changed the code as below, but it gives again Object Reference error.

    We tried to set ledgerdimension.Account Property and assign it to JournlLine assuming that it will take the account Name, but

    unfortunately it is throwing object reference error.

    AxdType_MultiTypeAccount ledgerDimension = new AxdType_MultiTypeAccount();
    ledgerDimension.Account = LedgerDimensionMainAccount;//"7101"; // Give the account number
    ledgerDimension.DisplayValue = LedgerDimensionMainAccountName;//"Staff salaries & Wages";
    journalLine.LedgerDimension = ledgerDimension;
    
    if (journalLine.AccountType == AxdEnum_LedgerJournalACType.Cust)
    {
        //AxdType_MultiTypeDefaultAccount defaultDimension = new AxdType_MultiTypeDefaultAccount();
        //defaultDimension.Account = LedgerDimensionMainAccount;
    
        AxdType_DimensionAttributeValueSet defDimension = 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 };
    
        defDimension.Values = new AxdType_DimensionAttributeValue[1] { difdimValue1 };
        //journalLine.LedgerDimension = ledgerDimension;
    
        journalLine.DefaultDimension = defDimension;
    
        //journalLine.DefaultDimension = 5637147626;
        //AxdType_DimensionAttributeValueSetStorage dimStorage;
    }

  • Suggested answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: C# code to create General Journal with default Dimension not working

    Perhaps this discussion helps: stackoverflow.com/.../general-journal-aif-services-cant-import-offsets-account-of-type-customers-ax

    Although it says that AX itself seems to support only account types Ledger and Bank when using this service. But it also says that you might be able to make a customization in AX to enhance it.

  • Maisamali Momin Profile Picture
    10 on at
    RE: C# code to create General Journal with default Dimension not working

    Example.jpeg

  • nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: C# code to create General Journal with default Dimension not working

    Could you please set up such a record in AX and share a screenshot with us? Thanks!

  • Maisamali Momin Profile Picture
    10 on at
    RE: C# code to create General Journal with default Dimension not working

    There should be value 'EMP0104' in Account field.

  • nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: C# code to create General Journal with default Dimension not working

    Ok, and would you want to have some value in the Account field?

    Could you please verify with the AX team what is the expected outcome here. Only then it makes sense to discuss possible adjustments to the code.

  • Maisamali Momin Profile Picture
    10 on at
    RE: C# code to create General Journal with default Dimension not working

    Yes working but when we post journalLine with default dimension, then Account is coming blank

  • nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: C# code to create General Journal with default Dimension not working

    Is it working now?

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Martin Dráb Profile Picture

Martin Dráb 601 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 416

#3
Adis Profile Picture

Adis 384 Super User 2025 Season 1

Product updates

Dynamics 365 release plans