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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Calculate LineAmountMST from SalesParmLine

(0) ShareShare
ReportReport
Posted on by

Hi all,

What is the easy way to get the Line Amount MST (amount in company currency) if the starting point is from SalesParmLine table ?

I noticed in this table, we have LineAmount but this is not in MST and obviously there is Currency code as well to accompany it.

I'm creating a routine to check total amount during posting invoice process, and compare it to my custom Parameter table. Problem is this value is on company currency only, so I need to convert first the amount from SalesParmLine in the middle of posting process to company currency. 

Btw, I'm using CoC to extend class SalesFormLetter_Invoice : validate method for doing this.Is it the best place ?

The intention is after compare, if it is not satisfied, posting invoice will be terminated / canceled.

Thanks,

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    there are 2 classes one creates journal and another post it. So instead of working with SalesParmLine, you can work with the journal. For example,  custInvoiceTrans already has LineAmountMST that you can check and compare to your table in SalesInvoiceJournalPost.checkBeforePostingLine() method

  • VoltesDev Profile Picture
    on at

    Hi Ievgen,

    Thank you for your input. May I ask one more thing, what if instead line, I want to check the Total of that invoice ? So, it still Sum CustInvoiceTrans.LineAmountMST but in header (custInvoiceJour) level. I can use Sum CustInvoiceTrans in checkBeforePostingLine but it seems odd to put in there, does it ?

    Can you recommend the best method I can extend ?

    Thanks,

  • VoltesDev Profile Picture
    on at

    Hi Ievgen,

    I'm sorry, upon checking, CustinvoiceJour already has InvoiceAmountMST to keep the total amount, so I don;t need to sum anymore.

    So any suggestion what is the best method beside checkBeforePostingLine I can use, so it will only check one time only ?

    Thanks

  • Mea_ Profile Picture
    60,286 on at

    You can find another place or you can just check it with a first line and throw exception to stop posting, so you will check it only once.

  • VoltesDev Profile Picture
    on at

    Hi Ievgen,

    Alright, I follow what you suggested, to still use the method, and yes because in the original method it self, when it is not meet condition, it will throw error, so I follow the same.

    It looks fine, only got one issue, beside this checking I have a custom table to log any error. I think because in the end of the routine is ThrowError, does it RollBack any transaction ?

    Because when I debug at my own routine, it does inserting this table, but when continue, and the posting is canceled, my table is empty.

    Btw, another curiosity is, as this Throw Error is also a from standard method, what will happened if the Invoice posting is through a batch job ? will the batch job ended in the middle of its process ? lets say I want to process 100 SO, at SO #5 it hits the condition (lets say the original CheckBeforePostingLine, first), then the throw error will stop the batch job at #5 ?

    Sorry for my many questions..

    Thanks,

  • Martin Dráb Profile Picture
    239,992 Most Valuable Professional on at

    Yes, throwing an error interrupts the execution and roll back all active database transactions. You'll get back into the same state as before running the process.

  • VoltesDev Profile Picture
    on at

    Hi Martin,

    Noted. So what should I do for the error log (inserting some info to my custom table) ? any special method I should create first ?

    Thanks,

  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    You can either put your code outside of the transaction scope in catch statement and then log the error in your table (but you will have to understands that it's your error). Or use userConnection class to write data into your table in a different transactions

    https://community.dynamics.com/ax/b/klaasdeforche/posts/using-the-userconnection-class-to-create-a-new-transaction-scope

  • Verified answer
    Martin Dráb Profile Picture
    239,992 Most Valuable Professional on at

    It depends on what you want to achieve. A usual approach is simply logging all infolog messages at the end of execution. You can see in batch jobs, for example.

    If you explicitly require writing to database from inside a transaction that will be rolled back, you need a separate connection to database.

  • VoltesDev Profile Picture
    on at

    It works.

    Thank you both. You guys are very helpful.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Subra Profile Picture

Subra 371

#3
Martin Dráb Profile Picture

Martin Dráb 279 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans