Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

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

Posted on by 55

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

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 287,995 Super User on at
    RE: Refreshing Value Models for Fixed Assets when creating General Journal in AX 2012 x++

    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?

  • Sirus49 Profile Picture
    Sirus49 55 on at
    RE: Refreshing Value Models for Fixed Assets when creating General Journal in AX 2012 x++

    Any feedback on my reply?

  • ChrisJohansson Profile Picture
    ChrisJohansson 5 on at
    RE: Refreshing Value Models for Fixed Assets when creating General Journal in AX 2012 x++

    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());
    
                   }
    
             }

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: Refreshing Value Models for Fixed Assets when creating General Journal in AX 2012 x++

    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

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 287,995 Super User on at
    RE: Refreshing Value Models for Fixed Assets when creating General Journal in AX 2012 x++

    Hi Sirus49,

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

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... 287,995 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,610 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans