adsenseheader

Saturday, April 4, 2020

Get packing slip id for the Posted Invoice in Dynamics AX

Hi Guys,

If you are looking for code that needs to find a Packing slip Id for the posted Customer Invoice in Dynamics AX 365 for operations.

Below is the code that helps you out!


static void getPackingSlip(Args _args)
{
    CustInvoiceJour     custInvoiceJour;
    SalesParmTable      salesParmTable;
    CustPackingSlipJour custPackingSlipJour;
    SalesParmSubLine    salesParmSubLine;
    SalesParmLine       salesParmLine;

    custInvoiceJour = CustInvoiceJour::findRecId(35637193385);
    select firstOnly salesParmTable
        where salesParmTable.ParmId == custInvoiceJour.ParmId
            && salesParmTable.Ordering == DocumentStatus::Invoice;

    //in case of mulitple packing slip selected in invoice
    while select DocumentId from salesParmSubLine
            exists join salesParmLine
            where salesParmSubLine.LineRefRecId == salesParmLine.RecId
                && salesParmLine.ParmId          == salesParmTable.ParmId
                && salesParmLine.TableRefId      == salesParmTable.TableRefId
    {
        select firstOnly custPackingSlipJour
            where custPackingSlipJour.PackingSlipId == salesParmSubLine.DocumentId
                && custPackingSlipJour.SalesId == salesParmTable.SalesId;
        info(strFmt("%1-%2-%3-%4",custPackingSlipJour.DeliveryDate,custPackingSlipJour.PackingSlipId,salesParmTable.SalesId,custInvoiceJour.InvoiceId));
    }
}

Thursday, April 2, 2020

Post Partial Purchase Order Lines through Code in AX 365 for opeartions

Hi Guys,

The below code shall help you to post the Purchase order line level Product receipt posting. Basically, its a partial Product receipt posting.

     public static void main(Args _args)
    {

                   Query        query;
                   SysQueryRun        queryRun;
                   QueryBuildDataSource qbds;


                      ttsbegin;
select firstonly1 purchLinePost
                        where purchLinePost.InventTransId == "xxxxx";

    query = new Query(QueryStr(PurchUpdatePackingSlip));
                    qbds = query.dataSourceTable(tableNum(PurchLine));
                    qbds.addRange(fieldNum(PurchLine, RecId)).value(queryValue(purchLinePost.RecId));
                    queryRun = new SysqueryRun(query);

                    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
                    purchFormLetter.chooseLinesQuery(queryRun);
                    purchFormLetter.update(icPurchTable,icPurchTable.PurchId);
                    ttscommit;
      }

Note: Use SysQueryRun object instead of QueryRun.

Happy Daxing!!

Regards,
Pradeep