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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Replacing Sales Order invoice number in x++

(0) ShareShare
ReportReport
Posted on by 59

We are doing some integration and creating sales orders in x++.  We would like to replace the generated INV-XX-XX invoice number from the invoice number coming from the 3rd party system.

This is not the Sales order number which i know how to do.. its just the Invoice number.  This seems easy to replace in Purchase orders but for some reason its more difficult to find for sales orders... thanks

*This post is locked for comments

I have the same question (0)
  • nmaenpaa Profile Picture
    101,160 Moderator on at

    First you need to find the place in code where the invoice number is initialized. Did you already find it?

    Before writing any code there, you need to consider the process.

    What if the user invoices the order in multiple parts? Or creates one invoice from multiple orders? How do you want it to work in those scenarios?

  • Sirus49 Profile Picture
    59 on at

    This is coming from an integration and will be a 1 line sales order and invoiced immediately so not worried about that.  No i'm looking where to set this haven't found that yet.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    You can check cross references for CustInvoiceJour.InvoiceId field and see which methods write to this field.

    This general advice will help you find such info yourself in the future, cross references are your friend!

  • Sirus49 Profile Picture
    59 on at

    I know it ends up there.. but i'm just trying to find how to set that when i'm setting up my Sales order.. i'm using salesTable, SalesLines. SalesParmTable and SalesParmLine , SalesFormLetter

  • Suggested answer
    Satish Panwar Profile Picture
    14,671 Moderator on at

    Hi Sirus49,

    We don't know how and when are you invoicing the orders.. invoicing right after the order creation in same call or afterwards. Anyway, here is how you can make it work:

    1. Store the invoice number in a field on the sales order.

    2. When you post the invoice, instead of using the number sequence, get the value from salesTable.customField where you will store the invoice number. Once you initialize, system will post using the same invoice number. By default there is no invoice number setup on sales order, it's retrieved during invoicing routine but in your case you will get it from the field where you store data. you won't be able to save this in salesParmTable/line/salesformletter as they are all initialized from salesTable/line only.

    This will make sure your codebase always work whether you call invoicing routine from external system or from within AX. Be cautious about partial invoicing and what should happen in these cases. If your orders are fulfilled outside then just invoice the entire order in single invoice.

    Thanks,

    Satish Panwar

    Please help verify answer(s) if they guide you in right direction so other community members can also benefit from your question with verified answer.

  • Sirus49 Profile Picture
    59 on at

    I'm not doing any partial invoicing , literally just creating and invoicing the entire sales order in 1 shot. no concerns here just need to override the invoice number.  Ok but where exactly do I initiate where I can override with the new invoice number..

    " it's retrieved during invoicing routine but in your case you will get it from the field where you store data" how do i override this part?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Did you already find where the invoice number is assigned to the invoice? In the same area you might notice that SalesId is actually also initialized and written to CustInvoiceJour. So, when you find this standard code, you can use the SalesId to get your SalesTable, and if SalesTable.CustomField (your new field) has value, use it as invoice number instead of fetching invoice number from number sequence.

    Is it now clear on high level?

  • Satish Panwar Profile Picture
    14,671 Moderator on at

    Hi Nikoloas,

    I think Sirus is looking for actual code where he can set it. and we are asking him to utilize cross reference to find out the actual codebase.

  • Suggested answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    Look at the class SalesInvoiceJournalCreateBase method initJournalHeader , following piece of code is responsible for creating invoice ID .

    custInvoiceJour.InvoiceId = this.getJournalNumber();

    You can do coc on this method to override standard invoice ID with your new one.

  • Sirus49 Profile Picture
    59 on at

    Thanks,  i was trying to find it by cross references but i had to update them and it has been taking forever...

    I guess i'm just wondering why for Purchase orders its so easy to set as a parameter but for sales orders it doesn't accept a parameter and you have to override the base code.  Thing is we have multiple companies and not all companies are going to want have this overridden and even within the company that we are doing the integration. Its only for certain scenarios that we want to override this.  So i guess I would have to implement some logic to only override for this specific situation and if that invoice num is set in a certain field on the sales table.  Is this good practice to do this? i guess its the only way.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans