Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

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

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
    Maisamali Momin 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
    Martin Dráb 225,672 Super User 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
    Maisamali Momin 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
    nmaenpaa 101,148 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
    Maisamali Momin 10 on at
    RE: C# code to create General Journal with default Dimension not working

    Example.jpeg

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 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
    Maisamali Momin 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
    nmaenpaa 101,148 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
    Maisamali Momin 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
    nmaenpaa 101,148 on at
    RE: C# code to create General Journal with default Dimension not working

    Is it working now?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,420 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans