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

Refreshing Value Models for Fixed Assets when creating General Journal in AX 2012 x++

(0) ShareShare
ReportReport
Posted on by 59

I'm creating a journal entry through x++ with fixed assets.. I set the ledger transaction with a fixed asset account, save and then use ledger journal engine to "refresh" and trigger it so it sets the value model combination behind the scenes. It does set the value model, but when I go to validate it complains that its not set. When I click on the line and go validate, the error essentially Disappears and goes to the next line to complain. If i click on every line and click validate , the error goes away and eventually the journal is ok to post. My question is, is there something else to call or trigger where it will know that this is set properly without bringing up this error.

Here is a code snip below, I construct the journalTrans and set all the other parameters as well, journalNum, currency etc.

    ledgerJournalTrans ledgerJournalTrans;
    LedgerJournalEngine lje;

      AxLedgerJournalTrans                journalTrans;

     journalTrans = AxLedgerJournalTrans::construct();

journalTrans.parmAccountType(LedgerJournalACType::FixedAssets);
journalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger);

   journalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount("Fixed asset Account #",   LedgerJournalACType::FixedAssets));
   journalTrans.save();

   ledgerJournalTrans = journalTrans.ledgerJournalTrans();
   lje = LedgerJournalEngine::construct(ledgerJournalTrans.ledgerJournalTable().JournalType);
   lje.accountModified(LedgerJournalTrans);
ledgerJournalTrans.update();

pastedimage1592418086285v1.png
pastedimage1592418096713v2.png

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,354 Super User 2026 Season 1 on at

    Hi Sirus49,

    Did you use the debugger to see if the lje.accountModified method is actually setting the correct value for the value model?

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi,

    Why do you set the value model this way?

    Isn't the value model one of the elements that needs to be setup at the time the fixed asset is setup?

    I don't understand your business process.

    Would be great if you could describe in more detail.

    Many thanks and best regards,

    Ludwig

  • ChrisJohansson Profile Picture
    5 on at

    Yes the value model is already setup when the fixed asset is created.  When you enter the fixed asset manually through the front end form it all populates just fine.. I'm just trying to do it through code and get it to trigger through code that pulls in the value model... which is why i used this code below to trigger that... But when debugging it looks like it fails on class AssetPost / Check on  assetTrans.BookId which isn't set. So i found that If i use the code below by inserting ledgerJournalTrans_Asset. It then works.. But I have to set that BookId.  I included a job down below that will create a journal with a fixed asset and will pull in the value models but when you go to validate it complains, then goes away because something "gets refreshed" and probably sets this bookid.

     

    ledgerJournalTrans = journalTrans.ledgerJournalTrans();
    
      lje = LedgerJournalEngine::construct(ledgerJournalTrans.ledgerJournalTable().JournalType);
    
      lje.accountModified(LedgerJournalTrans);
    
      ledgerJournalTrans.update();
    
    if (journalTrans.ledgerJournalTrans().isFixedAssetsTransaction())
    
               {
    
                   ledgerJournalTrans_Asset.clear();
    
                   ledgerJournalTrans_Asset.initValue();
    
                   ledgerJournalTrans_Asset.RefRecId  = journalTrans.ledgerJournalTrans().RecId;
    
                   ledgerJournalTrans_Asset.AssetId   = journalTrans.ledgerJournalTrans().getAssetId();
    
                   ledgerJournalTrans_Asset.Company   = journalTrans.ledgerJournalTrans().getAssetCompany();
    
                   ledgerJournalTrans_Asset.TransType = AssetTransTypeJournal::Acquisition;
    
                   ledgerJournalTrans_Asset.BookId    = 'SL';
    
                   if (!ledgerJournalTrans_Asset.validateWrite())
    
                       throw Exception::Error;
    
                   ledgerJournalTrans_Asset.insert();
    
    }
    
    static void testGeneralJournal(Args _args)
    
    {
    
                GeneralJournal gj;
    
                str errorMsg;
    
                         ledgerJournalTrans          ledgerJournalTrans;
    
                         LedgerJournalEngine         lje;
    
                DimensionDefault              offsetLedgerRecid;
    
                   ledgerJournalTrans_Asset ledgerJournalTrans_Asset;
    
                   AssetTable                          assetTable;
    
               AssetBook                          assetBook;
    
               AssetLedgerAccounts        assetLedgerAccounts;
    
                    AxLedgerJournalTable  journalTable;
    
               LedgerJournalTable                  ledgerJournalTable;
    
               LedgerJournalName                   ledgerJournalName;
    
               AxLedgerJournalTrans                journalTrans;
    
               DimensionAttribute                  dimensionAttribute;
    
               DimensionAttributeValue             dimensionAttributeValue;
    
               DimensionAttributeValueSetStorage   dimStorage;
    
               LedgerDimensionAccount              ledgerDimension;
    
               container  ledgerDimensions;
    
               DimensionAttributeValueCombination  davc;
    
               System.Exception ex;
    
               int counter;
    
               VendTable vendTable;
    
         changeCompany("018") //Inserts into specified company
    
               {
    
                   try //Setup Journal
    
                   {
    
                       ttsBegin;
    
                       ledgerJournalName = LedgerJournalName::find('GenJrn');
    
                       journalTable = AxLedgerJournalTable::construct();
    
                       journalTable.parmJournalName(ledgerJournalName.JournalName);
    
                       journalTable.parmJournalType(ledgerJournalName.JournalType);
    
                       JournalTable.parmName("test");
    
                       journalTable.save();
    
                           journalTrans = AxLedgerJournalTrans::construct();
    
                           journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum); //Link trans to JournalNumber
    
                           journalTrans.parmTransDate(str2Date("06-18-2020",213)); //posting date
    
                           journalTrans.parmTxt("test"); //Description of expense
    
                           journalTrans.parmDocumentNum("test"); // Document Num
    
                           journalTrans.parmDocumentDate(str2Date("06-18-2020",213)); //month/day/year
    
                           journalTrans.parmInvoice("test"); //Invoice
    
                           journalTrans.parmCurrencyCode("USD");
    
                                    journalTrans.parmAccountType(LedgerJournalACType::FixedAssets);
    
                                    journalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger);
    
                                    journalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount("SomeAccount", LedgerJournalACType::FixedAssets));
    
                                    journalTrans.save();
    
                               ledgerJournalTrans = journalTrans.ledgerJournalTrans();
    
                               lje = LedgerJournalEngine::construct(ledgerJournalTrans.ledgerJournalTable().JournalType);
    
                               lje.accountModified(LedgerJournalTrans);
    
                           journalTrans.save();
    
                       ttsCommit;
    
                     }
    
                     catch (Exception::Error)
    
                     {
    
                         throw Exception::Error;
    
                     }
    
                   catch (Exception::CLRError)
    
                   {
    
                           ex = ClrInterop::getLastException();
    
                               if (ex != null)
    
                                   {
    
                                   ex = ex.get_InnerException();
    
                                       if (ex != null)
    
                                           {
    
                                              error(ex.ToString());
    
                                            }
    
                                   }
    
                          throw Global::Error(ex.ToString());
    
                   }
    
             }

  • Sirus49 Profile Picture
    59 on at

    Any feedback on my reply?

  • André Arnaud de Calavon Profile Picture
    303,354 Super User 2026 Season 1 on at

    Hi Sirus,

    The coding you shared is unclear. There is one method which should create a journal line and above that some coding without a method name. I don't know when this is called or not. Can you explain the relation between these two parts in the coding you shared?

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
André Arnaud de Calavon Profile Picture

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

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 375

#3
Adis Profile Picture

Adis 268 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans