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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Post sales order by code with selected lines

(1) ShareShare
ReportReport
Posted on by 125

Hi,

Just wondering if someone can put me in right direction. I need to post sales order in AX using x++. Below is the code which is working fine. Nevertheless, this code post the full sales order (All Lines). Whereas, we only want to invoiced those lines where due date is in past. Can someone please help.

salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);

salesTable = SalesTable::Find("SO-001");

SalesFormLetter.update(SalesTable,systemDateGet(), SalesUpdate::All, AccountOrder::None, false, false);

Regards,

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sohaib Cheema Profile Picture
    48,938 User Group Leader on at
    RE: Post sales order by code with selected lines

    Hi,

    here you go

    http://axlearning.blogspot.com/2014/01/partial-sales-order-through-code-in.html

    use document status as per your need whether to invoice confirm or receive. Logic should be same 

  • André Arnaud de Calavon Profile Picture
    299,509 Super User 2025 Season 2 on at
    RE: Post sales order by code with selected lines

    Hi Ayesha,

    Can you explain what you mean with your words "where due date is in past"?

    There is out of the box no option to invoice sales orders based on a due date.

  • Ayesha Profile Picture
    125 on at
    RE: Post sales order by code with selected lines

    Hi Andre,

    our salesline table is as follow

    LineNum: SalesId : Item number : Shipping date requested

    1: SO001 : It1 : 01/03/2015

    2: SO001 : It1 : 01/04/2015

    3: SO001 : It1 : 01/01/2016

    I just want to invoice the first two lines because they are in past and not the third one where shipping date requested is 01/01/2016.

    Regards,

  • Ayesha Profile Picture
    125 on at
    RE: Post sales order by code with selected lines

    Hi Sohaib,

    Thanks I have tried this code but this table doesnt have that field I would like to put filter on.

    Regards,

  • Verified answer
    André Arnaud de Calavon Profile Picture
    299,509 Super User 2025 Season 2 on at
    RE: Post sales order by code with selected lines

    Hi Ayesha,

    The link provided by Sohaib can be a bit useful. You can use it, but it needs additional coding to evaluate the dates. Also some parts needs to be customized to meet your scenario. This code does create an invoice for all lines initially.

    In the part where a loop is done through the parmLines, you need to find the original sales order line (SalesLine) based on the Lot ID (InventTransId). Then you can evaluate if the line should be deleted or not.

  • Verified answer
    Ayesha Profile Picture
    125 on at
    RE: Post sales order by code with selected lines

    Thanks Andre,

    Issue has been resolved :) . I am supplying the code below just in case if someone needs the same.

       SalesFormLetter salesFormLetter =  SalesFormLetter::construct(DocumentStatus::Invoice);

       SalesTable salesTAble;

       SalesParmLine parmLine;

       SalesLine salesline;

       salesTable = SalesTable::find('AU-027333');

       salesFormLetter.salesTable(salesTAble);

       salesFormLetter.transDate (systemDateGet());

       salesFormLetter.specQty (SalesUpdate::All);

       //If you want proforma you can enable the code

       salesFormLetter.proforma (true);

       salesFormLetter.printFormLetter (true);

       salesFormLetter.createParmUpdateFromParmUpdateRecord(salesFormLetter.salesParmUpdate());

       salesFormLetter.initParmSalesTable(salesTAble);

       salesFormLetter.initParameters(salesFormLetter.salesParmUpdate(),Printout::After);

       salesFormLetter.initLinesQuery();

       while select forUpdate parmLine where parmLine.ParmId == salesFormLetter.parmId()

       {

           salesLine = salesline::findInventTransId(parmLine.InventTransId);      

           if (salesline.ShippingDateRequested > today())

           {

               ttsBegin;

               parmLine.delete();

               ttsCommit;

           }

       }

       salesFormLetter.run();

  • Sohaib Cheema Profile Picture
    48,938 User Group Leader on at
    RE: Post sales order by code with selected lines

    Hi bro,

    sorry for a delayed response, as I was busy.

    see we can control this using query, I have done it myself also 1 time. I was not having access to client machine, so I was unable to get code, nor I was having time to rewrite code.

    see here an example below, despite, you already resolved it

    microsoftdax.blogspot.com/.../ax-2012-post-partial-sales-order-using.html

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans